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

My Debounce is not working properly?

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

✓ Accepted answer

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.

6 comments

0

Edited.

0

I was so hopeful but nope...

0

After the intial debounce, you can spam fire

0

I'll try it again.

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.

0

Im using a tool thats why. So perhaps thats it?

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

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)

8 comments

0

Yep, nope. Thanks though

0

I can still spam fire, so nope.

0

maybe... Change Firing to Firing = true ?

0

Represents the same thing.

1

i edited my ans

0

mhm...really appreciate the effort my dude, sadly, its not working either.

0

How could it doesn't work.......I test it and it was working.. :/

0

I edited the script (again) and i HOPE my script will WORK :v, btw if this doesn't work then... i give up

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