I don’t understand, that’s a non-problem. A button is meant to be clicked multiple times. What specifically is your issue? Are your functions running when you click the button when it should be debounced or what? You need to be explicit and include as much detail as you can about the problem you’re facing. I can’t understand the issue or help you solve it if the responses are vague.
My best guess is that debounce was a variable created locally in the function, which would mean the debounce variable is local to the function only and doesn’t apply to any other calls, but I wouldn’t know this for sure without more context.
If there is any error in the output, could you post a screenshot of it?
Other than this, it looks like debounce should be false after 1.5 seconds, since all the calls here are instantaneous.
Actually i’m kinda confused, if the user clicks it should block them from clicking once more and creating 2 of the same gui’s this is why I created a debounce variable in the first place to solve this issue. Is there another way to keep a user from clicking multiple times at the same time?
There’s literally no issue with that script. You’ve successfully declared debounce as an upvalue (please change it to a local variable, not a global) and there’s nothing inherently wrong with the script etiher.
local debounce = false
if not debounce then
debounce = true
-- Your code
I don’t understand at all what you mean by this. Where exactly are two Guis being created? Please provide details. A screenshot, or something to work with would be appreciated. I can’t see any kind of duplication in your code so I’m not sure where you’re getting that from.
That’s not the appropriate way to solve the problem. You don’t prevent clicking, you prevent functions from running when the debounce state is active (variable is set to true). Buttons are meant to be clicked multiple times.
I seriously do not understand the problem at hand here, because there is none. Are you referring to the fact that the button changes colours on each click? That’s done by the Gui backend. Disable AutoButtonColour if you don’t want that happening. Otherwise, I don’t know what the problem is here.
There’s no difference between using a BoolValue and a debounce variable. One relies on a physical object in the hierarchy and another is in-script. That’s useless overhead and won’t change the outcome. The use of a local upvalue in-scope is fine as it is.