Defining a GUI element while the script is somewhere else

Greetings everyone!

I’m studying programming in Lua for almost 1 year but now, since i am tired and haven’t worked on scripting that much lately (i’ve been building) , i forgot how to define a GUI button, in my case, when the script is somewhere else. For an example, the script is located in StarterPlayerScripts and i want to print “Hello” when i click a button inside StarterGui.

Yes i know this might sound ridiculous but i honestly forgot and cannot remember.

As i said above, all i want to know is how to define a GUI while the script is somewhere else so i can script a button which prints “Hello” upon pressing.
image

local guiButton = script.Parent
guiButton.MouseButton1Click:Connect(function()
print("Hello")
end

Then define the enire path, in your case, the path would be:

game.Players.LocalPlayer.PlayerGui.Menu.BackFrame.Home

But you would have to use wait for child or it will error:

game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("Menu"):WaitForChild("BackFrame"):WaitForChild("Home")

image
Even tho i get this possible error, the script prints hello. Does this “problem” will affect the script or the game’s FPS in any way?

No, it doesn’t make a noticeable difference. You don’t really have to worry about that breaking the performance, that’s a warning that you don’t have the “Menu” ScreenGui found in PlayerGui.

1 Like