Something about debounce

When scripting a TextButton, you can use debounce for making a cooldown or use it for “open&close” guis, right?
So here’s the question, what is the difference about:

local debounce = false

script.Parent.TextButton.MouseButtonClick1:Connect(function()
if debounce == false then
debounce = true

> Code here

end)

and


local debounce = true

script.Parent.TextButton.MouseButtonClick1:Connect(function()
if debounce == true then
debounce = false

> Code Here

end)

Functionality wise, there is no difference.

They are the same. Both ways should work.

the debounce being true or false makes no difference we only using it to tell if we should allow the function


-- the debounce value has to be anything but can not be 69 because if it is 69 then the function can never pass the if check
local debounce = nil

script.Parent.TextButton.Activated:Connect(function()
    -- if the debounce value is 69 then return and exit the function preventing the code below from running
    if debounce == 69 then return end
    -- if the code managed to get here that means debounce was not 69 and we went past the if check above
    -- now lets set the debounce to 69 so that if the button is pressed again the if check will prevent this part of the code running again
    debounce = 69


    -- code here


    -- lets wait 1 second before changing the debounce value from 69 to something else
    task.wait(1)
    -- now we have to set the debounce to anything but 69 so that if the button is pressed again we can pass the if check
    debounce = "ANY Value but cant be 69 or the if check above wont pass"
end)
1 Like