Simple tween gui is not working

whoever solves this simple problem i am having will get a solution

I am making a shop. You click the TextButton to open the Frame and you click the X button to close the Frame. Simple.

The problem is when I open the shop and I use the X button instead of the open button to close the Frame, when I try to open the Frame again I have to click the Open button twice. I’ve tried everything I can think of to solve my problem but came up with nothing and here is my code in the open button

local Visible = false

local Button = script.Parent
local Frame = Button.Parent.ShopFrame

Frame.Position = UDim2.new(0.5, 0, 1.5, 0)
Frame.Visible = false

Button.MouseButton1Down:Connect(function()

	if not Visible then

		Frame.Visible = true

		Frame:TweenPosition(UDim2.new(0.5, 0, 0.5, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.25,
			false)

		task.wait(0.5)
		
		Visible = true

	else
		
		Frame:TweenPosition(UDim2.new(0.5, 0, 1.5, 0),
				Enum.EasingDirection.Out,
				Enum.EasingStyle.Sine,
				0.25,
				false)

			task.wait(0.5)

			Visible = false
			Frame.Visible = false

	end
	
end)

and here is the code in my X button located inside of the frame

local Visible = false

local Button = script.Parent
local Frame = script.Parent.Parent

Button.MouseButton1Down:Connect(function()
	
	Frame:TweenPosition(UDim2.new(0.5, 0, 1.5, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.25,
		false)

	task.wait(0.5)

	Visible = false
	Frame.Visible = false
	
end)

The local Visible variable is only accessible in the script where it was defined. But you can get the frame’s visibility from the frame’s properties, which can be read from both scripts. (I’ve just removed them and edited the logic in the if statements.)

--Open button script
local Button = script.Parent
local Frame = Button.Parent.ShopFrame

Frame.Position = UDim2.new(0.5, 0, 1.5, 0)
Frame.Visible = false

Button.MouseButton1Down:Connect(function()
	if not Frame.Visible then
		Frame.Visible = true
		Frame:TweenPosition(UDim2.new(0.5, 0, 0.5, 0),
			Enum.EasingDirection.Out,
			Enum.EasingStyle.Sine,
			0.25,
			false)
		task.wait(0.5)
	else
		Frame:TweenPosition(UDim2.new(0.5, 0, 1.5, 0),
				Enum.EasingDirection.Out,
				Enum.EasingStyle.Sine,
				0.25,
				false)
			task.wait(0.5)
			Frame.Visible = false
	end	
end)
--X button script
local Button = script.Parent
local Frame = script.Parent.Parent

Button.MouseButton1Down:Connect(function()
	Frame:TweenPosition(UDim2.new(0.5, 0, 1.5, 0),
		Enum.EasingDirection.Out,
		Enum.EasingStyle.Sine,
		0.25,
		false)
	task.wait(0.5)
	Frame.Visible = false
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.