I have been trying to make a shop but it is not working

So i made an in game item shop but for some reason whenever i click the buy button it sets the coin to 0 and then starts to work the way it should…

Here’s a screenshot

On the buy click event, the code is changing the text before the variables. So, it’s always going to be a click behind by showing the previous value. As far as showing zero, the code needs to update the text object’s current values somehere outside of the button click events like when this scene or popup is displayed.

Also, the click events don’t need trigger once bc you can only click once per frame.

This is before clicking the buy button

Preview of Avalon 6_29_2023 1_36_36 PM

This is after clicking the buy button
Preview of Avalon 6_29_2023 1_36_55 PM

what should i do?

Are you updating the text object with the current value when this screen is loaded and did you reverse the order of the actions so the variable gets changed before the text object is set to.

At some point, you’ll need to add a check so the player can’t buy something if they don’t have enough money. Something as simple as money
≥ value of item. You could either add a popup or disable or hide the button.

How did you set and display the 30?
Your variable Money is 0 before you buy anything.

I just wanted to check if it is working so i changed it to 30 but i only changed the text

1 Like

Okay then the result -10 is correct.

2 Likes

Sorry for the late reply
It was my fault

and yes i will be adding the mechanic to check if the player can buy something or not with the amount of money they have
again thank you very much!

1 Like

I see
then it was my mistake
but thank you very much for your help!!