This Tween script doesnt work, (SOLVED)

I’m making a script that Tweens two Guis off the screen when you click a button, and when you click the button again it tweens onto the screen, but it ain’t working for me

here

button = script.Parent
frame = button.Parent.Open
fram = button.Parent["Shop Open"]


button.MouseButton1Click:Connect(function()
	if frame.Position == UDim2.new(0.048, 0,0.499, 0) and fram.Position == UDim2.new(0.048, 0,0.422, 0) then
	frame:TweenPosition(UDim2.new(-0.048, 0,0.499, 0),"Out","Quad",0.5)
		fram:TweenPosition(UDim2.new(-0.048, 0,0.422, 0),"Out","Quad",0.5)
	elseif frame.Position == UDim2.new(-0.048, 0,0.499, 0) and fram.Position == UDim2.new(-0.048, 0,0.422, 0) then
		frame:TweenPosition(UDim2.new(0.048, 0,0.499, 0),"Out","Quad",0.5)
		fram:TweenPosition(UDim2.new(0.048, 0,0.422, 0),"Out","Quad",0.5)
	end
end)

thanks!

Maybe its because its meant to be else not elseif (I’m comparing videos of TweenGUI to urs)

that makes a bunch of red lines under my code

Well did your original script had any errors, and if so can you send an image of it.

nah, no errors

[ignore this text]

strange, maybe try adding a print to check if that line of code is even running.
(Sometimes scripts won’t work and wouldn’t send out any errors.)

button = script.Parent
frame = button.Parent.Open
fram = button.Parent["Shop Open"]


button.MouseButton1Click:Connect(function()
	if frame.Position == UDim2.new(0.048, 0,0.499, 0) and fram.Position == UDim2.new(0.048, 0,0.422, 0) then
	frame:TweenPosition(UDim2.new(-0.048, 0,0.499, 0),"Out","Quad",0.5)
		fram:TweenPosition(UDim2.new(-0.048, 0,0.422, 0),"Out","Quad",0.5) print:("Works!")
	elseif frame.Position == UDim2.new(-0.048, 0,0.499, 0) and fram.Position == UDim2.new(-0.048, 0,0.422, 0) then
		frame:TweenPosition(UDim2.new(0.048, 0,0.499, 0),"Out","Quad",0.5)
		fram:TweenPosition(UDim2.new(0.048, 0,0.422, 0),"Out","Quad",0.5) print:("Works!")
	end
end)

Nothing in the output!

I appreciate the attempts to help me

Maybe instead of doing if try functions, maybe that could work

Like make a boolvalue toggle to keep on track of the button

ok Ill just try to do it a different way

If its set to true that means it’ll turn on the frame, if its false then it’ll close the frame.

I recommend not using frame.Position in the if statement.
Instead, just have a boolean that toggles when you change between the open and closed state.

button = script.Parent
frame = button.Parent.Open
fram = button.Parent["Shop Open"]

local is_open = false

button.MouseButton1Click:Connect(function()
  is_open = not is_open
  if is_open then
   -- tween the fram and frame to where you want for when it is in the open state
  else
  -- tween the fram and frame to where you want for when it is in the closed state
  end
end)
2 Likes

Thanks for the help
thanks for the script referance TigerCaptian, it worked!

(idk who to give solution tho)

I think you meant to use or rather than and?

Here is your fixed script:

button = script.Parent
frame = button.Parent.Open
fram = button.Parent["Shop Open"]


button.MouseButton1Click:Connect(function()
	if frame.Position == UDim2.new(0.048, 0,0.499, 0) or fram.Position == UDim2.new(0.048, 0,0.422, 0) then
	frame:TweenPosition(UDim2.new(-0.048, 0,0.499, 0),"Out","Quad",0.5)
		fram:TweenPosition(UDim2.new(-0.048, 0,0.422, 0),"Out","Quad",0.5)
	elseif frame.Position == UDim2.new(-0.048, 0,0.499, 0) or fram.Position == UDim2.new(-0.048, 0,0.422, 0) then
		frame:TweenPosition(UDim2.new(0.048, 0,0.499, 0),"Out","Quad",0.5)
		fram:TweenPosition(UDim2.new(0.048, 0,0.422, 0),"Out","Quad",0.5)
	end
end)
button = script.Parent
frame = button.Parent.Open
fram = button.Parent["Shop Open"]

local toggle = false

button.MouseButton1Click:Connect(function()
	toggle = not toggle
	if toggle then
		--tween
	else
		--tween
	end
end)
1 Like

Thanks for the support tho I fixed my problem! :melting_face:

try this

button = script.Parent
frame = button.Parent.Open
fram = button.Parent["Shop Open"]


button.MouseButton1Click:Connect(function()
	if frame.Position == UDim2.new(0.048, 0,0.499, 0) and fram.Position == UDim2.new(0.048, 0,0.422, 0) then
		frame:TweenPosition(UDim2.new(-0.048, 0,0.499, 0),"Out","Quad",0.5)
		fram:TweenPosition(UDim2.new(-0.048, 0,0.422, 0),"Out","Quad",0.5) print:("Works!")
	else 
		frame:TweenPosition(UDim2.new(0.048, 0,0.499, 0),"Out","Quad",0.5)
		fram:TweenPosition(UDim2.new(0.048, 0,0.422, 0),"Out","Quad",0.5) print:("Works!")
	end
end)