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

My Debounce is not working properly?

Asked by 5 years ago
Edited 5 years ago
01Mouse.Button1Down:Connect(function(Mouse)
02    local Firing = true
03    if Active and Firing then
04        Firing = false
05        Dead()
06        TankRnd()
07    end
08    wait(5)
09    Firing = true
10end)

This is my code to fire my Tank cannon basically but I cannot seem to get the debounce to work properly and then you can spam fire it which is no bueno...

Any help would be greatly appreciated.

3 answers

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

The answer is the debounce has got to check if the firing is not false, which will then set it to true. You could make this look simpler by not putting it on the same line, but checking that both of them are correct to continue with your script.

Not entirely sure if this will work, but it's worth a shot.

Code:

01local firing = false
02 
03Mouse.Button1Down:Connect(function(Mouse)
04    if active then
05        if not firing then
06            Firing = true
07            Dead()
08            TankRnd()
09            wait(5)
10            firing = false
11        end
12    end
13end)

Please accept my answer if this works for you.

0
Edited. RyanTheLion911 195 — 5y
0
I was so hopeful but nope... Decimaprism 65 — 5y
0
After the intial debounce, you can spam fire Decimaprism 65 — 5y
0
I'll try it again. RyanTheLion911 195 — 5y
View all comments (2 more)
0
I've edited it, I can't see how this wouldn't work. It should repeat the debounce now as the firing = false was outside. RyanTheLion911 195 — 5y
0
Im using a tool thats why. So perhaps thats it? Decimaprism 65 — 5y
Ad
Log in to vote
1
Answered by 5 years ago
01Mouse.Button1Down:Connect(function(Mouse)
02    if Active then
03        if not Firing then
04            if Firing then
05                return
06            end
07            Firing = true
08            Dead()
09            CreateBullet()
10            wait(1.5)
11            Firing = false
12        end
13    end
14end)

This is it. Figured it out.....thank you all so much for all the help. Really appreciate it

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

The problem is (I think) is you need to put wait(5) and Firing =true in the if statement in order it to work and you have to set local firing = true outside the function block so the script should be

01local Firing = true
02 
03Mouse.Button1Down:Connect(function(Mouse)
04    if active then
05     if Firing then
06        Dead()
07        TankRnd()
08    wait(5)
09    Firing = true
10    end
11    end
12end)
0
Yep, nope. Thanks though Decimaprism 65 — 5y
0
I can still spam fire, so nope. Decimaprism 65 — 5y
0
maybe... Change Firing to Firing = true ? Nguyenlegiahung 1091 — 5y
0
Represents the same thing. Decimaprism 65 — 5y
View all comments (4 more)
1
i edited my ans Nguyenlegiahung 1091 — 5y
0
mhm...really appreciate the effort my dude, sadly, its not working either. Decimaprism 65 — 5y
0
How could it doesn't work.......I test it and it was working.. :/ Nguyenlegiahung 1091 — 5y
0
I edited the script (again) and i HOPE my script will WORK :v, btw if this doesn't work then... i give up Nguyenlegiahung 1091 — 5y

Answer this question