server script there is nothing that is changing the value xept this i have checked many times my script:
local tool = game.ReplicatedStorage.Tools.Sign local remote = game.ReplicatedStorage.Tools.Buy_Sign print("runned") -------------------------------------------------- remote.OnServerEvent:Connect(function(player,Vorth) ------------------------------------------------ local coins = player:WaitForChild("leaderstats").Coins ------------------------------------------------- --remove coins coins.Value = coins.Value - 5 --Move tool to the player and set id. tool.Parent = player.Backpack end
Hello, Freddan2006YT!
I think the only thing missing on your script is a debounce variable, it prevents the code from running twice on a small time period
I've added it to your script
local tool = game.ReplicatedStorage.Tools.Sign local remote = game.ReplicatedStorage.Tools.Buy_Sign local deb = false --Variable used for debounce print("runned") -------------------------------------------------- remote.OnServerEvent:Connect(function(player,Vorth) if(deb == false)then -- Lets code execute if variable "deb" is false deb = true -- Prevents code from running again ------------------------------------------------ local coins = player:WaitForChild("leaderstats").Coins ------------------------------------------------- --remove coins coins.Value = coins.Value - 5 --Move tool to the player and set id. tool.Parent = player.Backpack wait(0.5)--Wait 0.5 before making code able to run again deb = false end end
Edit¹: Also, this prevents hackers/exploiters from flooding their money change(or others)
Edit²: It would be good if you add something to check if player money is less than 5, so the player would not be able to have negative money
If I helped, please upvote and mark answer as accepted
I have kinda fixed it I'm very confused why I need to do this to make it work someone explain if you know why
local tool = game.ReplicatedStorage.Tools.Sign local remote = game.ReplicatedStorage.Tools.Buy_Sign local deb --Variable used for debounce -------------------------------------------------- remote.OnServerEvent:Connect(function(player) if not deb then -- Lets code execute if variable "deb" is false deb = true -- Prevents code from running again ------------------------------------------------ local coins = player:WaitForChild("leaderstats").Coins ------------------------------------------------- --remove coins coins.Value = coins.Value - 5 tool.Parent = player.Backpack wait(0.5)--Wait 0.5 before making code able to run again deb = false coins.Value = coins.Value +5 end end)