If the debounce is inside the function, other functions cant use it, if the debounce is outside the function or global variable then any function can use it
it wont run at the same time, you need coroutines to do that coroutine | Roblox Creator Documentation. It will run when the previous function is done or i think so
Hi. It really depends on what you want to achieve. If you use a debounce for all your functions then as soon as one function activates the debounce, the rest will stop working until the debounce is deactivated by the function that activated it. If you don’t want that, then each function should have its own debounce.
The functions won’t run at the same time, they run in succession so the first function call will use the debounce (debounce becomes true, then false), then the second function will be able to use the debounce (that has been set to false previously).
Functions only run at the same time if you use coroutines.
ok. but the debunce pattern is used in threads, so there is no point in using it in normal functions. In that case debounce pattern would not be used but flags.
The short answer is yes you can. Put the debounce variable at the top of the script, then you can use it freely within nests. However, I’m not sure why you’d want to use one debounce for all buttons rather than one for each button.
By default, all code is executed serially, which means one after the other. Even if you use multiple scripts or coroutines, it will be impossible for their to be conflict like that. The only way that’s possible is if you use Parallel Luau, so you won’t have to worry about that.
My point is that it doesn’t matter in this case (no debounce is needed). It’s also not easier or harder to use one or multiple debounces. But I believe I’ve already answered your original question in #12.
Every variable stated as a local inside a function is for that function only.
Anything stated outside the function is local to the entire code.
It has nothing to do with the order.
Outside the function it is really a global variable, as in global to the entire code.
Inside the function it is really a local variable, as in local to only that function …
here explains in detail what flags are. In your case, as you are using normal functions, then what you are using is not debounce but flags. Just change the name.