Daily Scripting Tips [ Tip #1 ] | Use :WaitForChild() over direct references for safer, more reliable scripts

local player = game.Players.LocalPlayer
local gui = player:WaitForChild(“PlayerGui”):WaitForChild(“MainUI”)

:white_check_mark: Prevents errors if the object hasn’t loaded yet
:x: player.PlayerGui.MainUI can break if it doesn’t exist immediately

:brain: Why? Roblox loads assets more efficiently—WaitForChild() makes your script wait until the object is there.

Infinite yield posible on WaitforChild(“MainUI”)

1 Like