What am I doing wrong here
Will either have no highscore or says 0
Develop games in your browser. Powerful, performant & highly capable.
I don't see anything wrong. Run the game in debug mode and check the value of Highscores variable.
Also, you can get rid of "On exists" and "On get" events to make the code shorter:
On Start of Layout LocalStorage Check if "Highscores" exist System Wait for previous action to complete Set Highscore to LocalStorage.ItemValue Set HSText text to Highscore
I changed that but I'm getting NaN as a result now
Add "Local Storage Clear" action, run the project once. Then disable/remove this action, see if this will fix the error.
I think LocalStorage uses strings, not numbers, so you have to convert it to int if you're setting a number based variable to that value.
For example,
Set Highscore to int(LocalStorage.ItemValue)
Local Storage can use both numbers and strings. I'm guessing it saved invalid number (NaN) once and this is causing the issue.