Debounce does not work

hey, I have a script but my debounce is not working for some reason. I’ll provide you with a small block of code that works intentionally but the debounce doesn’t (hence the post!)


local db = false
	game.Workspace.LargeTasseledScarf.Handle.ClickDetector.MouseClick:Connect(function(E)
		if not db then
			db = true
			local player = game.Players:GetPlayerFromCharacter(E.Parent)
			leaderstats["Hats Collected"].Value = leaderstats["Hats Collected"].Value + 1
			wait(1900000000000000000000000000000000000000000000000000000000000000000000000000000000000)
			db = false
		end
	end)

I know I could’ve done math.huge but that didn’t work so I tried that and didn’t work either.

(there are no unknown variables, no errors in the output)

Is this code actually firing, have you tried adding prints to debug and see what’s happening at runtime?

it is firing, please read my post fully.

okay, so is the db value just not changing? have you tried printing what db is equal to when the button is pressed?

Edit: I did, but you said this is a small block of code from it, so I don’t know whats around it, and if something may be blocking the thread before-hand…

What do you mean printing the value?

Also, yes it is firing, I am able to click and the value does go up by 1.

The wait is way too long, it is -1 because int overflow. Make it lower, see a different result.

AKA no wait because you’re using a numer so large, that it just goes back to -1, which means no wait.

To confirm, run this in your studio.
print("a") wait(1900000000000000000000000000000000000000000000000000000000000000000000000000000000000) print("hi")
Everything will happen immediately, but with
print("a") wait(5) print("hi")
It’ll take 5 seconds to print hi.

More info:

alright, that works, gotta be more careful with integers next time, but how come math.huge didn’t work? have another script with the almost exact same intentions yet math.huge seems to work on that script only, not my one right now.

Because math.huge is not a defined number, it’s just infinite, so it’s way over 9.2 quintillon. Weird though, happy that worked. Don’t forget to mark solution!

Edit: spelling

You could just get rid of the wait and the debounce altogether if your intention is to only allow the code to run once.

2 Likes