Leaderstats reseting when given more

whenever i buy something from the shop and pick up another coin i get reset the the amount of coins i had when i didnt purchase the walkspeed for 1000 coins


and heres the scripts u might need
coin spawner
walkspeed purchsaes

The problem is that the shop is subtracting on the client side but not the server side. This means that when a coin is picked up and updated (which seems to be on the server side), the server doesn’t know that the client subtracted anything, and it overwrites the client value. In other words, the server’s data always overrides the client’s data.
To fix this, use a RemoteEvent. When the player buys the upgrade, use RemoteEvent:FireServer(coins,speed) to tell the server to subtract the coins value and change the WalkSpeed. On a server Script, use RemoteEvent:OnClientEvent(plr,coins,speed) to receive the event and make the changes.

2 Likes

If you’re running the code on a Client Script (THE BLUE ONE) use a Server Script (THE WHITE ONE) instead as what happens on the client doesn’t happen on the server.

Stuff needs to happen on the server to:

  • prevent cheats
  • saving data
  • data validation
  • many more reasons

Stop using wait() use task.wait() its better and its not deprecated (depreciate = not support and removing soon (aka oneday) )

i havent really learned how to use remote events so can i have a little bit more help? im still sorta a begginner

Check out this link for a full breakdown
However I’ll give you an overview.
Remote events are basically instances that allow one-way communication between the server (like god, the one who watches and manages all) and the client (the player). This allows you to script stuff on one side that affects the other. In your case here, you can do what rohbot said in post #1 by setting up a remote event in rep storage first. Make sure to use correct syntax

ok ill use it, thank you for the video