Script Issue; Tweening Position

Hey everyone! :wave:

I’m currently trying to make a basic tween position script for a GUI that makes a seperate ScreenGui pop up on the player’s screen when a button is clicked, but I’m receiving an error.

Here is my script:

local button = script.Parent
local Menu = script.Parent.Parent.Parent.Parent.Parent.Menu.FirstPage

button.MouseButton1Click:Connect(function()
Menu:TweenPosition(UDim2.new(0.237, 0,0.196, 0), "Out", "Back")
end)

Here is my layout, 1 is the gui that I want to pop up and 2 is the script location:

Here is the error I’m receiving:
image

Any help with this would be greatly appreciated! :grinning_face_with_smiling_eyes:

You are most likely getting the wrong path to the Menu

What would be the correct path to do so?

Use :WaitForChild("Menu") as it’s probably not loaded in yet and the client is indexing something that doesn’t exist yet.

2 Likes

This worked; thank you so much! :grinning_face_with_smiling_eyes:

Edit: Also, thanks to the people who were typing up a reply to this post as I can see, much appreciated.

Alongside using :WaitForChild() on the object, for future reference, it’s more intuitive and reliable to reference the GuiObject via the PlayerGui folder rather than repeating .Parent, especially if the hierarchy is ever adjusted at any point.

local Players = game:GetService("Players")
local player = Players.LocalPlayer

local PlayerGui = player:WaitForChild("PlayerGui")

local button = script.Parent

button.Activated:Connect(function()
    local Menu = PlayerGui:WaitForChild("Menu")
    local FirstPage = Menu:FindFirstChild("FirstPage")

    if Menu and FirstPage then
        -- Tween the GuiObject here
    end
end)
3 Likes

C a l m d o w n, basically you’re parenting the Menu variable to:

Script > Menu > MainFrame > Frame > Buttons > StarterGui > (Attempting to find Menu) > (Attempting to find FirstPage)

You should just get the PlayerGUI instead so that it’s an easier approach

2 Likes