TweenPosition for a frame?

Hey!

I am trying to make a gui pop up using TweenPosition but the “animation” does’t load in.

Here is my code:

local playerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local gui = game.StarterGui.Starter

gui.Parent = playerGui

script.Parent.MouseButton1Click:Connect(function()
local cook = gui.CookFrame
cook:TweenPosition(UDim2.new(0,0,1,0)"InOut","Linear",0.5)
end)

It doesn’t show up when I press the button.

Any help?

2 Likes

Im guessing InOut makes it go away, but what is the alternative to make it appear?

1 Like

Startergui clones all the guis to the playerguis for you, you’re not supposed to do this.

Instead do:

local gui = PlayerGui.Starter
1 Like

Hmm.

There is nothing in the output - maybe I should try print statements?

The updated code is:

local playerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local gui = playerGui.Starter


   script.Parent.MouseButton1Click:Connect(function()
	local cook = gui.CookFrame
	cook:TweenPosition(UDim2.new(0,0,1,0)"InOut","Linear",0.5)
end)

What should I try next?

1 Like

You’re missing a comma before the “InOut” part.

1 Like

I have tried that - and yet the same result.

I will try debug it and get back to you all.

2 Likes

Is it a local script or a script?

1 Like

This is a local script inside of the button.

1 Like
local PlayerGUI = game.Players.LocalPlayer.PlayerGui

script.Parent.MouseButton1Click:Connect(function()
	local CookFrame = PlayerGUI.CookFrame
	CookFrame:TweenPosition(UDim2.new(0,0,0.5,0),"InOut","Linear",0.5)
end)

try this now.

1 Like

Does the output show the error of the script?

1 Like

Nope, no errors, I have tried print statements but i don’t think I did them correctly hahaha.

1 Like

Maybe use the WaitForChild function when wanting the playerGUI because it might not load straight away.

local PlayerGUI = game.Players.LocalPlayer:WaitForChild(“PlayerGui”)

1 Like
local TweenService = game:GetService("TweenService")
local TweenAnimation = Tweeninfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false)
local PlayerGui = game.Players.LocalPlayer.PlayerGui

script.Parent.MouseButton1Click:Connect(function()
	local Frame = PlayerGUI.CookFrame
	local Tween = TweenService:Create(Frame, TweenAnimation, {Position = UDim2.new(0,0,0.5,0)})
    Tween:Play()
end)

If still experiencing errors, try advanced version of Tweening.

2 Likes

It must be loaded because Parent of this script is PlayerGui, which loads faster than script.

1 Like

Ok, is there any way to find what Tweeninfo is? Is it part of TweenService or?

It is DataType. like option of tweening. TweenInfo

Yes, my bad - I just made a typo that’s all.

Ill see if this works!

1 Like

Hmmm. Still nothing…

Would this sort of script work on a SurfaceGui on a part?

Hmm. These sort of script will work in GUI object if all of object is set correctly.

Afaik, SurfaceGuis won’t register mouse inputs if the Adornee property of the SurfaceGui isn’t specified. The Adornee property should be the part that the surface gui is attached to