function onTouched(hit) local debounce = false local human = hit.Parent:findFirstChild("Humanoid") local genfire = script.Parent.Fire:clone() if (human ~= nil) and debounce == false then debounce = true genfire.Parent = human.Parent:findFirstChild("Torso") wait(5) genfire:Destroy() wait(10) debounce = false end end script.Parent.Touched:connect(onTouched)
genfire is a variable and i am destroying it after five seconds, but i tested this and the debounce broke
The issue is that a new debounce variable is declared each time the part is touched.
So it's "local" to that one touch and not "global".
What you should be doing is declaring it at the top so the function writes to and reads the same variable each time and not a new one each time
local debounce = false script.Parent.Touched:Connect(function(part) local humanoid = part.Parent:FindFirstChild("Humanoid") if humanoid and not debounce then debounce = true local genfire = script.Parent.Fire:Clone() genfire.Parent = humanoid.RootPart -- RootPart is a property of humanoid wait(5) genfire:Destroy() wait(10) debounce = false end end)
I also cleaned up the code and removed deprecated items, like :clone
, :findFirstChild
, :connect
which are deprecated in favour of the uppercase versions.