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?

01local Tool = script.Parent
02local Handle = Tool:WaitForChild("Handle")
03local Debounce = true
04Tool.Activated:Connect(function()
05    if Debounce == true then
06        PlantBomb()
07        Debounce = false
08        wait(3)
09        Debounce = true
10    end
11end)
12 
13function PlantBomb()
14    local Bomb = Handle:Clone()
15    Bomb.Parent = workspace
View all 25 lines...

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.

1local Debounce = false —Debounce should always be set to false, not true.
2Tool.Activated:Connect(function()
3    if Debounce == false then
4        Debounce = true
5        PlantBomb()
6        wait(3)
7        Debounce = false
8    end
9end)

Answer this question