Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is my debounce variable not working?

I'm making a dynamite tool, but for some reason the debounce doesn't work and you can spam click to spawn more dynamite. Any fixes?

local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local Debounce = true
Tool.Activated:Connect(function()
	if Debounce == true then
		PlantBomb()
		Debounce = false
		wait(3)
		Debounce = true
	end
end)

function PlantBomb()
	local Bomb = Handle:Clone()
	Bomb.Parent = workspace
	Bomb.CanCollide = true
	Bomb.Anchored = false
	Bomb.Transparency = 0
	wait(3)
	local Boom = Instance.new("Explosion")
	Boom.Parent = workspace
	Boom.Position = Bomb.Position
	Boom.BlastRadius = 16
	Bomb:Destroy()
end

2 answers

✓ Accepted answer

Here's a quickie, you should put the debounce = false before PlantBomb() located on line 6.

Don't worry, it'll make a lot more sense once you do it.

Put the debounce changer at the start. As it calls the function then changes the debounce. It needs to change the debounce then call the function.

local Debounce = false —Debounce should always be set to false, not true.
Tool.Activated:Connect(function()
    if Debounce == false then
        Debounce = true
        PlantBomb()
        wait(3)
        Debounce = false
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.