Hi I was making a shop script and when I started to put a debounce in it all it did was when I opened the shop and tried to close it. The close button didn't work. Can you help?
local frame = script.Parent.Parent.Parent.Frame2 local stop = false function click() if not stop then stop = true if frame.Visible == false then script.Parent.Text = "Close" frame.Visible = true frame:TweenPosition(UDim2.new(0, 300, 0, 0), "Out", "Back", 1) elseif frame.Visible == true then script.Parent.Text = "Shop" frame:TweenPosition(UDim2.new(0, 300, 0, -350), "Out", "Quad", 1) stop = false wait(0.9) frame.Visible = false end end end script.Parent.MouseButton1Click:connect(click)
The problem is the stop variable.
The condition you set,
if not stop then
makes it so that the none of the code that hides the frame runs.
A simple solution is to rearrange how you organized your script. Instead of limiting the elseif condition to run when stop is false, we will allow it to run if the stop variable is true.
Also a tip, you do not have to check for "== true" instead, you use if (condition) then or if (not condition) then.
local frame = script.Parent.Parent.Frame local stop = false function click() if not stop then stop = true if not frame.Visible then script.Parent.Text = "Close" frame:TweenPosition(UDim2.new(0, 300, 0, 0), "Out", "Back", 1) wait(1) frame.Visible = true stop = false else script.Parent.Text = "Shop" frame:TweenPosition(UDim2.new(0, 300, 0, -350), "Out", "Quad", 1) wait(1) frame.Visible = false stop = false end end end script.Parent.MouseButton1Click:connect(click)