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.
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:
01 | debounce = false --create the debounce, it can be named anything. |
02 | function touch() |
03 | if debounce = = true then return end --If the debounce is true, the function will end using return. |
04 | debounce = true --The debounce is now true. |
05 | print ( "Touched!" ) |
06 | wait( 5 ) --So the code cannot be repeated for 5 seconds. |
07 | debounce = false --The debounce is now false and the code can be repeated again. |
08 | end |
09 |
10 | workspace.Part.Touched:connect(touch) |
~coo1o