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
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)
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.