Scoring System

Hey everybody so i tried a high score system for my game but im running into a few issues with it which i need help on. Sorry i’m a beginner and still learning how to make a decent high score system.

Issue #1 : The score is displayed, but the “Best Score” is always 0 is there anyway to make best score show the previous highest score in the game? Pic

Issue #2 : So in my game the score system is not displayed in the beginning , but after the game ends it does not turn on. Is there anyway to display the score after the game ends? In the Pic i provided i had to manually turn it on in the hierarchy/Inspector view. I want it to turn on after the player has lost all their lives.

Here is my scripts

void OnGUI()
{

  if (playerLives == 0 && player == null) 
	
		{

		scoreTxt.text = "Score: " + score.ToString ();
		bestText.text = "Best: " + PlayerPrefs.GetInt ("Best");
		
		scoreTxt.gameObject.SetActive (true);
		bestText.gameObject.SetActive (true);
		
		}
  }

If you can help with my issue thank you!

Try getting your bestscore during Start()

For example…

private int bestScore;

Void Start () {
//get the current highscore.
bestScore = PlayerPrefs.GetInt ("Best");

}

// then modify the end to something like…

   if (playerLives == 0 && player == null) 
     if (score>bestScore) {

//set the new highscore

bestScore = score;

//save the new highscore.

PlayerPrefs.SetInt("Best",bestScore);
}
         {
 
         scoreTxt.text = "Score: " + score.ToString ();
         bestText.text = "Best: " + PlayerPrefs.GetInt ("Best");
         
         scoreTxt.gameObject.SetActive (true);
         bestText.gameObject.SetActive (true);
         
         }
   }

you may wish to check that as it hasn’t been tested but should point you in the right direction.

In terms of displaying your score during gameplay, have a look at the new 4.6 UI tutorials.