Tween Open and Close GUI

Hi all, for some reason my tweened open and close GUI fails to work. There are no errors in the output.

local frame = script.Parent.Parent.Clothingframe
local button = script.Parent

button.MouseButton1Click:Connect(function()
	if frame.Visible == false then
		frame.Visible = true
		frame:TweenPosition(UDim2.new(1,0.5,0.365, -15)) -- Put the position to tween to. 
	else
		frame:TweenPosition(UDim2.new(1.575,-20,0.365, -15)) -- Put the position to tween back to
		wait(3)
		frame.Visible = false
	end
end)

Thanks!

1 Like
local frame = script.Parent.Parent.Clothingframe
local button = script.Parent
local deb= false
button.MouseButton1Click:Connect(function()
if not deb then
deb=true
frame.Visible = true
frame:TweenPosition(UDim2.new(1,0.5,0.365, -15)) -- Put the position to tween to. 
elseif deb then
deb= false	
frame:TweenPosition(UDim2.new(1.575,-20,0.365, -15)) -- Put the position to tween back to
frame.Visible = false
end
end)
1 Like

Didn’t work unfortunately… Nothing happens when I click the button.

make sure the positions are correct

1 Like

i am sure you need more parameters inside

TweenPosition()

@Creeperman16487 oh ok thx

1 Like

Don’t forget to add the time how much it will be tweening and easing direction, style as well.

frame:TweenPosition(UDim2.new(1,0.5,0.365, -15), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 1)
1 Like

Use TweenService for tweening instead.

local tweenInfo = TweenInfo.new(
	2, -- Time
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
	true, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)
 
local tween = TweenService:Create(part, tweenInfo, {Position = Vector3.new(0, 30, 0)})
 
tween:Play()
2 Likes

well thats not true you can just put the positions and all of the other parameters will set to default

1 Like

thats not reccomended for gui like why use tweenservice when you have in built fuction for it?

1 Like

That function is limited, and is vulnerable - it’s recommended to use TweenService instead.

2 Likes

Updated script: (Still doesn’t work, not sure if I did it right)

local frame = script.Parent.Parent.Clothingframe
local button = script.Parent
local deb = false

button.MouseButton1Click:Connect(function()
	if not deb then
		deb = true
		frame.Visible = true
		frame:TweenPosition(UDim2.new(1,0.5,0.365, -15), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 1)
	elseif deb then
		deb = false	
		frame:TweenPosition(UDim2.new(-1,-0.5,-0.365, -15), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 1)
		frame.Visible = false
	end
end)

also i reccomend not changing the visible property and see if the frame is actully tweening or no

1 Like

try out this while putting the frame as visible true

local frame = script.Parent.Parent.Clothingframe
local button = script.Parent
local deb = false

button.MouseButton1Click:Connect(function()
	if not deb then
		deb = true
		frame:TweenPosition(UDim2.new(1,0.5,0.365, -15), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 1)
	elseif deb then
		deb = false	
		frame:TweenPosition(UDim2.new(-1,-0.5,-0.365, -15), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 1)
	end
end)
1 Like

Did that; its not tweening at all - it won’t move an inch.

what is the anchor point of frame?

1 Like

(0,0) - anchor points of the frame…

I am pretty sure it is with the second TweenPosition.
Try this

frame:TweenPosition(UDim2.new(0.44, 0,0.365, -15))

not

frame:TweenPosition(UDim2.new(1.575,-20,0.365, -15))

Let me know if it works!

1 Like
local frame = script.Parent.Parent.Clothingframe
local button = script.Parent
local deb = false

button.MouseButton1Click:Connect(function()
	if not deb then
		deb = true
		frame:TweenPosition(UDim2.new(1,0.5,0.365, -15), Enum.EasingDirection.InOut, Enum.EasingStyle.Linear, 1)
	elseif deb then
		deb = false	
		frame:TweenPosition(UDim2.new(0.44, 0,0.365, -15))
	end
end)

Have I done it correctly? It doesn’t work.

It looks like you forgot to add the tween properties to the second one

1 Like

check this code

local START_POSITION = UDim2.new(0,0,0, 0)
local GOAL_POSITION = UDim2.new(0.25,0,0.25,0)
local frame = script.Parent.Parent.Clothingframe
local button = script.Parent

frame.Visible=false
frame.Position=START_POSITION

button.MouseButton1Click:Connect(function()
  debounce=not debounce
  if debounce==false then
    frame.Visible=true
    frame:TweenPosition(GOAL_POSITION,Enum.EasingDirection.In,Enum.EasingStyle.Sine,2,true)
    print("open")
  else
    frame:TweenPosition(START_POSITION,Enum.EasingDirection.In,Enum.EasingStyle.Sine,2,true)
    wait(3)
    frame.Visible=false
    print("close")
  end
end)
```