:TweenPosition doesn't work on Frames [FIXED]

For some reason tweening a frame after the client has pressed a button doesn’t seem to work at all, here is the following script.

I’ve tweened many GUI objects in the past but for some reason it doesn’t seem to work. I didn’t add a parameter for the player because its a LocalScript.

4 Likes

Set the frame variable to this. Also, put the script inside the TextButton


script.Parent.MouseButton1Click:Connect(function()
local frame = script.Parent.Parent.ScreenGui.Frame
-- Tween here
end)
2 Likes

You’re tweening the position for the default gui, not the player’s gui.

local frame = script.Parent.Frame --Change this to the actual frame if needed
frame:TweenPosition(parameters)
1 Like

You are tweening frame thats in startergui and not in your playergui.

3 Likes

If so, I changed the script to this and is still not working.

Something that you should do is have the frame and button in the same ScreenGui, then from the LocalScript do script.Parent.Parent.Frame to get it.

I see many problems with the code you provided. Firstly, you shouldn’t be using game.Workspace at all, because the workspace doesn’t contain the StarterGUI.

What you should do is reference each GuiObject from the script:

local Frame = script.Parent.Parent.Parent.hmm.TextButton

Frame.MouseButton1Click:Connect(function()
    Frame:TweenPosition = {UDim2.new(0.475, 0, 0.411, 0)}
end)
2 Likes

you forgot the parameters even though they’re set by default, you should have them

local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local ScreenGui = PlayerGui:WaitForChild("ScreenGui")
local Frame = ScreenGui:WaitForChild("Frame")
local TextButton = PlayerGui.hmm.TextButton

TextButton.MouseButton1Click:Connect(function()
   Frame:TweenPosition(UDim2.new(0.475, 0, 0.411, 0), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 1)
end)

I might’ve written something wrong, if so then correct me, but once player enters the game, everything from StarterGui goes to PlayerGui, also make sure there isn’t another ScreenGui in the PlayerGui as that could cause an error or it might tween the wrong Frame
I still might be wrong though

2 Likes

The parameters are not needed, you would only need to set the Easing style and direction only if you want to change the defaults: Linear and Out

2 Likes

Sheesh, thanks for that! I didn’t even realise that I used workspace, I already know that the StarterGUI isn’t in the workspace but I always include it. I wish Roblox set a layout on the explorer which can push workspace to the right and the others to the left so that future devs will understand what is not in workspace and what is in workspace. Anyway, its basic, sorry for that!

2 Likes