Debounce won't bypass spam click

Why it won’t help for spam clicking?

upgradeButton.MouseButton1Click:Connect(function()
local debounce = true
	
	if player.leaderstats.Strength.Value >= currentUpgrade and debounce == true then
		debounce = false
		--codes here
                 task.wait(1)
		debounce = true
	elseif debounce == true then
		debounce = false
		--codes here
                task.wait(1)
		debounce = true
	end
end)

It’s because you’re setting the debounce after checking for clicks
should be like this instead

local debounce = true
upgradeButton.MouseButton1Click:Connect(function()	
	if player.leaderstats.Strength.Value >= currentUpgrade and debounce == true then
		debounce = false
		--codes here
                 task.wait(1)
		debounce = true
	elseif debounce == true then
		debounce = false
		--codes here
                task.wait(1)
		debounce = true
	end
end)
1 Like

you initialized it within the function, meaning its created inside the function and is not persistent. to fix, initialize debounce outside the function.

1 Like

Hey, I could be wrong but because you are defining the debounce variable as true on every click event it will always be true…

Just noticed wShadowRBLX beat me to it, let me know if this works though

try the following:

local debounce = true

upgradeButton.MouseButton1Click:Connect(function()	
	if player.leaderstats.Strength.Value >= currentUpgrade and debounce == true then
		debounce = false
		--codes here
                 task.wait(1)
		debounce = true
	elseif debounce == true then
		debounce = false
		--codes here
                task.wait(1)
		debounce = true
	end
end)
1 Like

thank you all!!! it work now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.