I need help on how to add a debounce because if I don't add that when people step on the part they will get many of the stat "Wins" in a second. Someone please help me!
"Wins" giver part script:
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then game.Players:FindFirstChild(hit.Parent.Name).leaderstats.Wins.Value += 1 end end)
local debounce = false --Bool Value script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if not debounce then debounce = true game.Players:FindFirstChild(hit.Parent.Name).leaderstats.Wins.Value += 1 wait() --Waits before turning debounce back to false debounce = false --Turns debounce back to false end end end)
If this didn't help, please don't downvote me. I'm really new to scripting and I'm just tryna' help. TY
The previous answer is still faulty; use 2 scripts, 1 is called "WinnerCount"; the other called "Resetter" make Resetter disabled & leave WinnerCount enabled; both in the part that is acting as your finishline.
WinnerCount:
script.Parent.Resetter.Disabled = true local debounce = false script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") and debounce == false then debounce = true local player = game.Players:GetPlayerFromCharacter(hit.Parent) player.leaderstats.Wins.Value = player.leaderstats.Wins.Value + 1 script.Parent.Resetter.Disabled = false wait(3) end end)
The Resetter script:
if script.Parent.CHANGEME.Disabled == false then script.Parent.CHANGEME.Disabled = true wait (30) --How long until the Finishline will work again, can be replace by a finishline position changer code line that undoes itself after a condition is met. script.Parent.CHANGEME.Disabled = false end