So I'm making a game where you sell stuff for cash and at first I had this pad the player would stand on to make them sell the item in a return of cash but suddenly it always had the player end up with 1001 cash. I changed this to a click detector button and it is still doing the same. In the leaderstats thing I had the player start with 1000 cash but even if I spent it all down to 200 cash it still, no matter what, brings it all the way back to 1001 cash. Can some one please help I am literally going insane. Here is the click detector button code:
local Button = script.Parent
Button.ClickDetector.MouseClick:Connect(function(player)
while player.Sodas.Value > 0 do
player.Sodas.Value = player.Sodas.Value - 1
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1
end
end)

3 comments
But the shop is in a gui and I used a local script, how would I make it actually subtract the cash on the server side?
client-server replication
remote events https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events