local enabled = true
x.Touched:connect(function(Hit)
if not enabled then
enabled = true
local HitPlayer = game.Players:GetPlayerFromCharacter(Hit.Parent)
if HitPlayer and HitPlayer ~= player and Hit.Parent:FindFirstChild("Humanoid") then
Hit.Parent.Humanoid:TakeDamage(20)
end
end)
wait(10)
enabled = false
✓ ANSWER ACCEPTED
Why isn't this debounce working?
2 answers
✓ Accepted answer
You actually have a couple things wrong here.
In the Touch event you have 2 if statements and only 1 end, along with the variable enabled being set to true on Line 1. Here is a cleaner and fixed version of your code.
local enabled = false
x.Touched:connect(function(Hit)
if not enabled then
enabled = true
local HitPlayer = game.Players:GetPlayerFromCharacter(Hit.Parent)
if HitPlayer and HitPlayer ~= player and Hit.Parent:FindFirstChild("Humanoid") then
Hit.Parent.Humanoid:TakeDamage(20)
wait(10)
enabled = false
end
end
end)
1 comment
0
Thanks.
The enabled value starts at true. On line 4, the conditional statement only allows the code below it fire if enabled is false. Just change enabled to false in the beginning and it will work.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Oh look somebody downvotes for no reason :D