Cannot change TMP UI text

Hello, I am a beginner with C# and unity in general. I have completed the renowned “Unity tutorial for complete beginners” by Game makers toolkit. I started adding more features to become more used to everything but for whatever reason I cannot find a fix to this specific problem.

I followed a few other tutorials on basic 2d additions like backgrounds and particles. I wanted to add a high score function so I followed “Setting and Saving High Scores in Unity” by Night Run Studio. I changed values and such accordingly and I do not receive any errors when the code is ran.


In the image, the large white text is the current runs score, which resets every run (Or fly I suppose). The yellow 0 should change into the current run score if it is higher. This does not happen.

This is the code to change high score.


I used the ‘debug.Log’ line to check if the code is reaching that point, which it is. I also had set the TMP text to blank, on death (Which is when ‘HighScoreUpdate()’ is called) it shows and sets to 0 no matter the current player score.

Sorry if this is formatted oddly, I am not sure the best way to present this issue. Hopefully it is a simple problem. Please let me know if you need any further pictures or details and thank you!

you failed to share what highscoretext is, and how you set it

highScoreText is the tmp that is not working, the yellowish 0 in the death image. I have it tied to the script running the code I showed earlier.


I have it attached like this.

Unless this is what I was missing, could you be a little more specific?

Ok but if you look at your code, you debug playerscore added but you show that if it saves or not, if it doesnt save then the saved value is still gonna be empty and your text wont update because you re-pull it from the saved area, rather than use the variable. I also dont see you save the playerprefs.

I think I figured it out, partly at least. I honestly just redid the code and it worked so I probably had a typo or something. Thanks!