Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why isn't my stop (Debounce) working?

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)

1 comment

0

Btw, you should consider reducing the tween time.

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.