how to make high scores using playerprefs

hello, I’m having a problem regarding in making a high score list…
I’m not fully understand the “if” statements, please help me to solve my problem…

there will be 3 to be stored in the playerprefs… then it will just sort from the highest to the third high score… this is my code…

void HighScores () {

		if (player.score >= highScore1 && player.score > highScore2 && player.score > highScore3) {
			highScore3 = highScore2;
			PlayerPrefs.SetInt (highScore_3, highScore3);
			highScore2 = highScore1;
			PlayerPrefs.SetInt (highScore_2, highScore2);
			highScore1 = player.score;
			PlayerPrefs.SetInt (highScore_1, highScore1);
		} else if (player.score < highScore1 && player.score >= highScore2 && player.score > highScore3) {
			highScore3 = highScore2;
			PlayerPrefs.SetInt (highScore_3, highScore3);
			highScore2 = player.score;
			PlayerPrefs.SetInt (highScore_2, highScore2);
		} else if (player.score < highScore1 && player.score < highScore2 && player.score > highScore3) {
			highScore3 = player.score;
			PlayerPrefs.SetInt (highScore_3, highScore3);
		}
			
	}

example my current score is 5, then the highScores output are 5,5,0… i don’t know why the second variable is 5… the output must become like this, 5,0,0… if i play again and example i gain 10pts… the output must become 10,5,0 but it became 10,10,0 …

Why do you make it so complicating?

public void Highscores()
{
    // Get latest highscore
    var first = PlayerPrefs.GetInt(highScore_1);
    var second = PlayerPrefs.GetInt(highScore_2);

    // Push first to second, second to third
    PlayerPrefs.SetInt(highScore_2, first);
    PlayerPrefs.SetInt(highScore_3, second);

    // Update first
    PlayerPrefs.SetInt(highScore_1, player.score);
}

I don’t think the error is in the saving part but rather in the loading code. Maybe you have a copy&paste error and you load the first highscore value into highScore1 and highScore2 ?

Though the saving code could be quite simplified as you have a lot unnecessary and redundant conditions.

if (player.score >= highScore1)
{
    highScore3 = highScore2;
    highScore2 = highScore1;
    highScore1 = player.score;

    PlayerPrefs.SetInt (highScore_3, highScore3);
    PlayerPrefs.SetInt (highScore_2, highScore2);
    PlayerPrefs.SetInt (highScore_1, highScore1);
}
else if (player.score >= highScore2)
{
    highScore3 = highScore2;
    highScore2 = player.score;

    PlayerPrefs.SetInt (highScore_3, highScore3);
    PlayerPrefs.SetInt (highScore_2, highScore2);
}
else if (player.score > highScore3)
{
    highScore3 = player.score;
    PlayerPrefs.SetInt (highScore_3, highScore3);
}

Since the high scores are always sorted from largest to lowest we don’t have to check if the new score is greater than the second and third if it’s already larger than the first one. Since we have an “else if” chain only one statement can be executed. So for the second you don’t have to check that the score is smaller than the first because you only reach the second if statement in case the first was not true.

Anyways your actual problem is not in the saving code.