What is debounce

So in every YT tutorial, I see this line where they set a variable called debounce, and set it to false. But why do they do that? What does it do?

18 Likes

A debounce, in short form, is a line of code, or rather, a variable, which is used to establish different Cooldowns, for example: Imagine a cashier, I want the user to be able to use it every 5 minutes, then with I can do a debounce by playing with booleans: True or False.

16 Likes

Its just another word for “Cool Down”.

6 Likes

Example:

--|| FederalTactical @ DevForum
local Part = game.Workspace:WaitForChild("Part")
local ClickDetector = Part:WaitForChild("ClickDetector")
local myDebounce = true --> The player would be able to click.

ClickDetector.MouseClick:Connect(function(Player)
	if myDebounce == true then
		myDebounce = false
		print("ClickDetector was used! \n Player Name: ", Player.Name)
		wait(5)
		myDebounce = true
	else
		return false;
	end
end)
21 Likes

debounce is like a cooldown

local deb = false
while wait() do
  if not deb then
    deb = true
    -- stuff
    wait(1)
    deb = false
  end
end
11 Likes

tysm this helped me out alot i been struggling on understanding it.

1 Like

As everyone already said this, I’ll just summarize:

Debounce Essentially just means:

  • Cooldown (90% of People that I know call it this)

  • Delay

It is used when you want to slow or delay certain points of your code:

Example of a Debounce:

local Debounce = false -- Our Debounce Variable

local DelayTime = 1 -- Our Delay time

function DebounceExample ()
if not Debounce then -- Checks if the Debounce is not equal to true (I believe)

Debounce = true -- Enables the Delay, function cant be used until false
print("Debounce Enabled")
task.wait(DelayTime) -- Wait time for delay
print("Debounce Disabled")
Debounce = false -- Disables Delay, Function can be used again

     end
end


while task.wait(Delaytime) do -- Example of a Debounce in a loop
DebounceExample()
end

8 Likes

Advice, DONT reply on a 1 year old topic or it will bump.

2 Likes

Just leave a like, not reply to this topic… If it helped just leave a heart so people know it helps lol

1 Like

Basically locking the function so no other code can run it agian and mess up the planned order,

and a example would be someone locking a door, and no one is getting trough, so with just a variable set to true or false you can make a debounce function, its not any official roblox function but its a practice for a lot of devs

btw why are people pumping this topic, its over 5 months old

4 Likes

Lets say it like this

Lets say a player buys an item, But you dont want the player buy the item rapidly.
You can use a debouce like this,

local debounce = false

if debounce then
   print('Debounce is on so we dont buy the item')
elseif not debounce then
   print('Debounce is off so we buy the item')
end
2 Likes