Thank you so much for your help, it works great!
It also made me realize another problem I have—I might be using local storage the wrong way.😂
Because after I used your code, every time I preview the game, it saves the global variable from the last session.