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

How to make a function not stack on itself?

I have a singular function, but whenever that function activates, the same function can be activated again. How do I prevent the function from happening, whilst the same function is functioning

example: I stand next to a sensor with the door, but since I'm standing with the sensor, the door slams me in the face and opens until I'm not in the sensor.

2 answers

✓ Accepted answer

A debounce is a boolean flag that you use to keep track of when the function is active and when it is not, implemented as such:

debounce = false

function YourFunction()
if not debounce then 
debounce = true
--Do your stuff
debounce = false
end
end

Add a debounce to the function, so the function will only run after it has been completely executed, or in your case, it will only run after you step off the sensor.

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