You can still click the textbutton multiple times
I was trying to use debounce so that wont happen
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.
This button is not supposed to be clicked multiple times. Otherwise 2 of the same gui appears and its a buggy mess.
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.
So is it this or not? Buttons are meant to be clicked multiple times, a debounce is a state variable meant to prevent your functions from running depending on your conditional statement.
You might want to fix the "
s in your snippet, they are obviously quotation marks, but it makes the code obfuscated.
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?
Instead of using a debounce, it would be wiser to create a BoolValue
inside of the button and set it to true when clicked, then change it back to false after the wait()
.
I’ll try this thank you. But doesn’t the debounce kinda act like a bool value anyway?
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
function click()
if not debounce then
debounce = true
-- Your code
end
end
script.Parent.MouseButton1Click:Connect(click)
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.
I’ve had the same issue before; I am not sure why this happens, but adding a BoolValue worked for me.
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.
I thought the same thing but for some reason I was having the same issue a while back and making that change fixed it for me, I don’t know why.
You’ll need to review your code when you get the chance then. Things don’t magically work because you use another method that’s the exact same as the original implementation.
this seemed to have fixed the issue looks like the issue was a matter of a .5 difference
On line 6 and line 10:
script.Parent.Parent.Parent:TweenPosition(UDim2.new(-0.02,0,-1), "Out", "Quad", 1, true)
You only used three numbers in UDim2.new
, which is super strange… does the fourth value just default to 0?
Yes. You could test this in Studio and see.
> local A = UDim2.new(1, 2, 3)
print(A.X, A.Y) --> 1, 2 3, 0
They all default to 0. UDim2.new() would give you 0, 0, 0, 0.
My fix was to set a bool value in the main GUI . If anyone else has this issue trying setting a bool value there instead
Try this: Forgot to re-address reply. Sorry, goldenstein64.
local debounce = false
local function click()
if debounce then
return
end
debounce = true
-- start code here
local UI = script.Parent.Parent.Parent -- easier to handle
local Clothing = UI.Parent.Clothing
script.Buy:Play()
UI:TweenPosition(UDim2.new(-0.02, 0, -1, 0), "Out", "Quad", 1, true)
wait(1)
UI.Visible = false
Clothing.Visible = true
Clothing:TweenPosition(UDim2.new(-0.02, 0, 0), "In", "Bounce", 1, true)
wait(1)
debounce = false
end
script.Parent.MouseButton1Click:Connect(click)
I discussed the problem with OP sometime earlier in the day. The main issue is that they had LocalScripts in each of their buttons, so the debounce was only local towards the button and not all of the buttons. I suggested that they either use a BoolValue as an external reference value or condense all of the button clicking logic into a single LocalScript; OP picked the former.
This new script would still face that same aforementioned problem.