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