Then all functions can use it since its global
I guess what I am really wondering is if multiple functions within a script run at the same time or if they wait until the previous function is done.
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
Thanks for the feedback.
I just didn’t want to setup a bunch of debounce values for each function within the script.
I wanted to make sure it won’t cause problems to use a common debounce for the entire script.
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
.
I am using it for a set of buttons inside a gui.
I don’t want people spamming the buttons and causing a crash.
So I though using one debounce would lock the functions out of running until the active function returns the debounce true.
Quoting myself from another topic:
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.
All of the buttons change values that are picked up by the buttons themselves.
So if two buttons get spammed it may cause a glitch in the values that are being picked up.
I can find no information on flags.
I found one post talking about a flag testing service for Roblox features:
But i’m not sure what it’s all about.
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.
So it won’t hurt to use one debounce then, right?
It makes it easier than having a bunch of unique debounces.
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.
I believe you did, yes. I was just confirming since this post went a little off track.
I just want one debounce.
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.
Oh, thank you.
I could not find any information on the Roblox website, but I did notice the examples provided by Roblox for a debounce
did not seem to match up with a the way I am using it.
Why would he be using flags, he is not verifying conditions.
And wouldn’t just doing return true
or return false
be easier?
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.