Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why is my debounce variable not working?

Asked by
Mr_Unlucky 1085 Moderation Voter
6 years ago

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

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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.

Ad
Log in to vote
0
Answered by
herrtt 387 Moderation Voter
6 years ago

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)

Answer this question