Setting highscore with PlayerPrefs not working

Hi

Im currently using this code to set a highscore for my player but the highscore number isnt displaying,the debug is working so the function is correct, anyone know what may be the problem or get a better solution?

public class Score : MonoBehaviour
{
    private static int score;
    public Text textscore;
    public Text bestScore;
    public GameObject Player;


    void Start()
    {
        score = 0;
        InvokeRepeating("ScoreUpdate", 1f, 1f);
    }

    void Update()
    {
        textscore.text = "Score: " + score;
        bestScore.text = "HighScore: " + PlayerPrefs.GetInt("bestscore");
        // + PlayerPrefs.GetInt("bestscore");
    }

    void ScoreUpdate()
    {
        if (Player)
        {
            score += 1;
            int highscore = PlayerPrefs.GetInt("bestscore", 0);
            if (score > highscore)
            {

                PlayerPrefs.SetInt("bestscore", score);
                Debug.Log("set highscore");

            }
        }

    }
}

Honestly, I’ve never used playerprefs in this way. I think though you have to use PlayerPrefs.Save though to record the value if you don’t change scenes or quit the app. I would say print out what PlayerPrefs.GetInt is returning for you…however, because of how often you could be doing this, it’s probably not a good idea to do that often.

I would suggest you pull the highscore once when a player starts and store that in a int. Then update that int. If a player loses the level, then you save the highscore to playerpref if it’s higher.

I’m also confused why you made score static…but that’s another issue…