Need help with frame tweening!

Hello, guys. I need someone to solve this script problem. There is an issue with my GUI, it will not let me to tween back even there is no error in the output. Anyone else?

local M = script.Parent.Parent.Parent:WaitForChild("SwirlyzMenu").Menu

script.Parent.MouseButton1Click:connect(function()
	wait(1)
	M:TweenPosition(UDim2.new(2.069, 0, 0.826, 0), 'Out', 'Quad',0.5)
	script.Parent.Text = "Close"
	wait(1)
script.Parent.MouseButton1Click:Connect(function()
	wait(1)
	M:TweenPosition(UDim2.new(10, 0, 0.826, 0), 'Out', 'Quad',0.5)
	script.Parent.Text = "Open"
	wait(1)
end)
end)

Thank you,
cory

Honestly, it’s probably because you nested the functions inside eachother. I would have a variable for whether or not the menu is currently open, and use that as my check.

local M = script.Parent.Parent.Parent:WaitForChild("SwirlyzMenu").Menu
local Open = false

script.Parent.MouseButton1Click:connect(function()
	if Open == false then
		Open = true
		wait(1)
		M:TweenPosition(UDim2.new(2.069, 0, 0.826, 0), 'Out', 'Quad',0.5)
		script.Parent.Text = "Close"
		wait(1)
	else
		wait(1)
		M:TweenPosition(UDim2.new(10, 0, 0.826, 0), 'Out', 'Quad',0.5)
		script.Parent.Text = "Open"
		wait(1)
		Open = false
	end
end)

In this case, when the button is clicked the script will check whether or not the menu is “open”. If not, open it & change the button text. If so, close it and change the button text.

Cheers!

1 Like

Also why are u adding a 1 second delay before opening the gui?

1 Like

I also questioned that but rolled with it, maybe he likes it that way :cowboy_hat_face:

1 Like

Whoo! Thank you so much! I carefully read your script, my brain got farted after reading it. I forgot to add if and then as it would help me to proceed the functions properly.

1 Like

I put a one second delay to prevent from people spamming the button.

I’m not 100% certain, but the way I wrote the code I’m pretty sure you could get rid of the waits and it wouldn’t matter if people spammed the button, it wouldn’t break it.

1 Like

Simply use the

local Open = false

as a debounce by doing

local M = script.Parent.Parent.Parent:WaitForChild("SwirlyzMenu").Menu
local Open = false

script.Parent.MouseButton1Click:connect(function()
	if Open == false then
		M:TweenPosition(UDim2.new(2.069, 0, 0.826, 0), 'Out', 'Quad',0.5)
		script.Parent.Text = "Close"
		wait(1)
       Open = true
	else
		M:TweenPosition(UDim2.new(10, 0, 0.826, 0), 'Out', 'Quad',0.5)
		script.Parent.Text = "Open"
		wait(1)
		Open = false
	end
end)