Fake intvalues?

I was trying to take away 150 coins from the leaderstats. After I took it away, I collected more, but it gave me the coins AND gave me the 150 coins I paid back. Is there anyone that can help with this topic?

1 Like

Sounds like you took it away only on your client (assuming you’re doing this in studio through the explorer). You can switch to the server by clicking the button near Stop in your top bar of studio.

2 Likes

This was from a script.
Yeah, you’re right and you helped part of it, but I’m also trying to solve how you can prevent that in a script.

1 Like

Are you asking how to prevent the 150 coins from coming back to you?

1 Like

Yes. It worked in my last simulator game. Since I’m doing a new one, I want to make it new and better.
For example, I get one per second and I waited 150 seconds to get enough. After I paid, it became 151, 152, and it kept going.

1 Like

I was expecting the value to be 0 after I paid, 1, 2, and so on.

1 Like

Ah so as @Synteuro was saying, it’s just a problem with what environment you’re making the change on (environment being only either the server or the client). If you’re reducing the coins on the client inside of a local script, then that change will only happen on the client. The server will see nothing changed, and when it updates to 151 your client will also update to 151.

To make the change happen on the server, you need to essentially “tell” the server that you’re buying something. You can achieve that with a remote event:
ReplicatedStorage.BuyRemoteEvent:Fire()

In a server script, you’ll hook into this event and make the necessary changes there:

ReplicatedStorage.BuyRemoteEvent.OnServerEvent:Connect(function(buyingPlayer)
    -- change the stat value
    leaderboard.Coins.Value -= 150
    -- any other changes could happen here as well, like rewarding the item they bought
end)

This way the server acknowledges that you’re making a purchase, deduct the appropriate coins, and that should replicate to your client without you needing to do anything else.

2 Likes

Thanks! It works now and I didn’t get the coins back.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.