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 4 years ago
Edited 4 years ago
Mouse.Button1Down:Connect(function(Mouse)
    local Firing = true
    if Active and Firing then
        Firing = false
        Dead()
        TankRnd()
    end
    wait(5)
    Firing = true
end)

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 4 years ago
Edited 4 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:

local firing = false

Mouse.Button1Down:Connect(function(Mouse)
    if active then
        if not firing then
            Firing = true
            Dead()
            TankRnd()
            wait(5)
            firing = false
        end
    end
end)

Please accept my answer if this works for you.

0
Edited. RyanTheLion911 195 — 4y
0
I was so hopeful but nope... Decimaprism 65 — 4y
0
After the intial debounce, you can spam fire Decimaprism 65 — 4y
0
I'll try it again. RyanTheLion911 195 — 4y
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 — 4y
0
Im using a tool thats why. So perhaps thats it? Decimaprism 65 — 4y
Ad
Log in to vote
1
Answered by 4 years ago
Mouse.Button1Down:Connect(function(Mouse)
    if Active then
        if not Firing then
            if Firing then
                return
            end
            Firing = true
            Dead()
            CreateBullet()
            wait(1.5)
            Firing = false
        end
    end
end)

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 4 years ago
Edited 4 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

 local Firing = true

Mouse.Button1Down:Connect(function(Mouse)
    if active then
     if Firing then
        Dead()
        TankRnd()
    wait(5)
    Firing = true
    end
    end
end)
0
Yep, nope. Thanks though Decimaprism 65 — 4y
0
I can still spam fire, so nope. Decimaprism 65 — 4y
0
maybe... Change Firing to Firing = true ? Nguyenlegiahung 1091 — 4y
0
Represents the same thing. Decimaprism 65 — 4y
View all comments (4 more)
1
i edited my ans Nguyenlegiahung 1091 — 4y
0
mhm...really appreciate the effort my dude, sadly, its not working either. Decimaprism 65 — 4y
0
How could it doesn't work.......I test it and it was working.. :/ Nguyenlegiahung 1091 — 4y
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 — 4y

Answer this question