Storing Score?

i don’t get it why me script is not working i can’t desplay the score :frowning:

void Start()
	{
		GameManager.HightScore.text = "Best: " + PlayerPrefs.GetInt("TimScore");
		if (GameManager.Score < PlayerPrefs.GetInt ("TimScore")) {
			PlayerPrefs.SetInt ("TimScore", GameManager.Score);
		}
	}

}

Your if statement seems to be in the start function. You have to move the if statement to somewhere where it is called after your game ends. Now it is called at the start only. You could for example make a boolean that turns true after the game is over. When just add that to your if statement and move the if statement to the update function.

If you are simply trying to display scores, then don’t use PlayerPrefs because PlayerPrefs is use for storing the data as an external file. If you are trying to store the data, then you are also missing PlayerPrefs.save()

Also, is it displaying the score but just not updating the score? or is it not displaying anything at all? Be specific.

If it is not updating the score then it is because you only set the text once in Awake (or Start from your original code). You need to change the text again when you change the score.

Also, does “TimScore” even exist in the PlayersPref when you use GetInt(“TimScore”) in the Awake()? Because if you never did PlayersPref.SetInt(“TimeScore”,score), or something like that, then the chances are when you use GetInt(“TimScore”) in Awake(), Unity is setting the text to nothing because TimScore does not exist in PlayersPref.