Debounce Issues

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?:
    → I want to make a debounce for my settings system.

  2. What is the issue?:
    → The debounce is not working.
    video of the problem

  3. What solutions have you tried so far?:
    → Looked on the dev forum and nothing helped.

script.Parent.Settings.Save.Activated:Connect(function()
	local cooldown = false
	print(cooldown)
	if cooldown == false then
		SendNotification("Debounce", "Debounce is false")
		cooldown = true
		print(cooldown)
	elseif cooldown == true then
		SendNotification("Debounce", "Debounce is true")
		print(cooldown)
	end
end)

You’re creating the cooldown as soon as the event is activated. You have to move the line and put it before it is activated to prevent spam clicking.

The issue is basically what @AlphaTheDragonMage said but let me re-word it because I don’t think it is super clear what they are trying to say and they missed out a bit.

The issue is that you are creating the variable called “cooldown” as soon as the Activated event is fired meaning that whenever this event is fired you create a variable called “cooldown” but set it to false meaning that the cooldown value will be always false because the way that functions linked to events work is that whenever the event is ran it will cause a new “cooldown” variable to be created.

To fix this issue you should be able to just simply just move the “cooldown” variable outside of the function. The other issue however is that you never turn the value back to false meaning that you never remove the cooldown. To fix this you can just wait an amount of time with wait() and then change the value to false again.

Something like this should work (I have not tested):

local cooldown = false

script.Parent.Settings.Save.Activated:Connect(function()
	if cooldown == false then
		local CountDown = 10
		SendNotification("Debounce", "Debounce is false")
		cooldown = true
		print(cooldown)
		wait(10)
		cooldown = false
	elseif cooldown == true then
		SendNotification("Debounce", "Debounce is true")
		print(cooldown)
	end
end)
1 Like

thats not really how a cool down works,

As Stated above, you are creating a Variable as soon as you Activate it, its best to put it outside,

Try this: (I have tested this)

local cooldown = false

script.Parent.Settings.Save.Activated:Connect(function()
	if not cooldown then
		SendNotification("Debounce", "Debounce is true")
		cooldown = true -- function no longer usuable
		print(cooldown)
	wait(2) -- Wait Time for Delay
cooldown = false -- function is usable again
		SendNotification("Debounce", "Debounce is false")
		print(cooldown)
	end
end)

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