Garlic clicker not working :(

so, for a little background: i’m working on a web game named garlic clicker, and i’ve tried to create a counter that displays how many garlic cloves you have, but when i attempted to set the text on the counter to the variable ‘cloveamount’ (which i’ve defined in a load script), it says that it’s undefined, what’s wrong with it?

Since you’ve defined the variable in a different script, the code is not reaching it.

You should connect the variable to an object or something you can point your code towards, so even when you’re in a different script it can find it. For example, connecting the variable to the object it’s written in— to do that, in your load script go where you set your variable and replace it with:

this.cloveamount = 0; 

You can replace the 0 with whatever amount you want to set it to by default.
Then, in your other script, rather than using " cloveamount ," use " this.cloveamount " to refer to the variable.

Let me know if this doesn’t work

Well, it could be because it’s not a window variable. Window variables can be referenced in any coding box throughout the frame. You can make it a window variable by saying:

window.cloveamount = 0;