I am new to scripting, I tried to use debounce in this script, it does not seem to work, why? Also is my spacing/organization/neatness done correctly? Not fully sure how to order them and make the script neat.
script.Parent.Touched:Connect(function(hit) local players = game:GetService("Players") --To get the service of players local playerHumanoid = hit.parent:WaitForChild("Humanoid") local hitfromPlayer = players:GetPlayerFromCharacter(hit.parent) --Getting the Player from its Character local debounce = false if not debounce then debounce = true if hitfromPlayer then playerHumanoid.WalkSpeed = playerHumanoid.WalkSpeed + 5 print("work pls") wait (5) debounce = false end end end)
Everytime you touch the part it resets the debounce, hence not making it wait for the cooldown. Put the debounce outside of the function.
local debounce = false script.Parent.Touched:Connect(function(hit) local players = game:GetService("Players") --To get the service of players local playerHumanoid = hit.parent:WaitForChild("Humanoid") local hitfromPlayer = players:GetPlayerFromCharacter(hit.parent) --Getting the Player from its Character if not debounce then debounce = true if hitfromPlayer then playerHumanoid.WalkSpeed = playerHumanoid.WalkSpeed + 5 print("work pls") wait (5) debounce = false end end end)