Variable is increasing without adding

this is the first time i write here.but i was getting help from this page a lot.
i have
`public int gold=100;
public int cost=5

//in the function i use it like this

gold-=cost;
`
the problem is that i have popup window and i open it to buy the things.cost is 5 and i lose 5 gold for each click.then i close and reopen popup window and this time when i wanna buy, cost become 10 and decreasing 10-10…close and reopen popup, then its 15-15.its adding but i dont want to add.

So what can i do ?

You’re somehow duplicating your script each time you open the popup. If you look in the hierarchy, you will probably see a new game object created each time you open the popup, and that game object has the script on it that’s updating the values. When you close and reopen you’ll likely see another new game object with the script, and so on.

That’s a wild guess, but it seems to fit the symptoms. If you want something more detailed you’ll need to provide more information as others have said.

okay i solved.problem was i didnt call onclick.removealllisteners();
after that everything works fine