Hello, fellows. I’ve coded a shop system that when you buy an item, it’s supposed to subtract your number of funds, which is a NumberValue inside a folder called “Status” inside of the player. However it seems like it is subtracting more then it really should. How can I fix this?
I’ve used
I guess to get a little bit of a better understanding of the problem, When I set my funds value to 10 and buy an item for $5 in the shop, it sets it to 0, even though it should just subtract 5.
I’ve noticed that this is in a local script. You should handle things like this in the server because the server won’t know that you took money from the player, and most likely give you lots of problems.
I’m confused, it should only subtract when the remote event is fired, and in the server code I don’t know how it would subtract itself twice. Can you please elaborate?
maybe add a debounce variable that could prevent it from happening twice
local Subtracted = false
game.ReplicatedStorage.Remotes.changeFunds.OnServerEvent:Connect(function(plr, numberoffunds)
if not Subtracted then
Subtracted = true
plr:WaitForChild("Status").funds.Value = plr:WaitForChild("Status").funds.Value - numberoffunds
wait(0.1)
Subtracted = false
end
end)