Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Debounce

I have absolutely no idea what the debounce property does, if it even is a property, or how to use it.

I've looked in almost every page, blog, and even memorized a few. I still don't know how to use it at all. I know it prevents certain functions from repeating an excessive amount of times, but I just can't grasp anything else about it.

1 answer

Debounce is actually a variable. Of course it's a boolean value and the way it works is a script checks if it's true and if it is, the function will end using return. It's really useful for the Touched event.

Example:

debounce = false --create the debounce, it can be named anything.
function touch()
if debounce == true then return end --If the debounce is true, the function will end using return.
debounce = true --The debounce is now true.
print("Touched!")
wait(5) --So the code cannot be repeated for 5 seconds.
debounce = false --The debounce is now false and the code can be repeated again.
end

workspace.Part.Touched:connect(touch)

~coo1o

2 comments

1

On line one, you use debounce and then you start using d. However, you should note that you do not need to define the variable at the top of the script for this code to work.

0

Thanks for pointing out that error of mine and yes, I know that you don't need to define it at the beginning. I'm just making an example.

This discussion is preserved as it was. New answers, comments, and votes are closed.