How do all you fellow scripters/UI creators deal with this?

I just have a short question for all of you out there. How do you deal with this?
image

Yes, I do define what I want to change as variables at the beginning when scripting, but it’s always like: “script.Parent.Parent.Parent.Parent”

1 Like

Just because it’s more clean, I always define the Parent ScreenGui directly from the Player’s PlayerGui. I then reference the other elements, from under that ScreenGui.

Player = game.Players.LocalPlayer

ScreenGui = Player.PlayerGui:WaitForChild("ScreenGui")

HolderFrame = ScreenGui.HolderFrame
ImageLable = HolderFrame.ImageLable

--ect
2 Likes

@ExcessEnergy Thanks I’ll try that out tomorrow, I haven’t had much practice with WaitForChild. So, if I’m correct, it basically searches through children, grandchildren, ancestors, stuff like that, until it finds something with that name?

2 Likes

WaitForChild is a method that when called, will continuously search for a object of the Name you provide, until it finds it.

In this case, I used it to make sure that the LocalScript doesn’t try to reference the GUI elements, before they have been loaded. Using the . method when the object doesn’t exist yet, will throw a error, and possibly break your script. WaitForChild is just a way to ensure that this doesn’t happen.

2 Likes