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)
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)
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)