Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Debounce

Asked by 10 years ago

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

Log in to vote
2
Answered by
coo1o 227 Moderation Voter
10 years ago

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

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. User#11893 186 — 10y
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. coo1o 227 — 10y
Ad

Answer this question