Player GUI not loading in time

I’ve got a problem where the script is supposed to get the gui, but I get the error “Ammo is not a valid member of PlayerGui”. I can only assume that it is not loading in time because the explorer tab is all correct.

local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local textLabel = playerGui.Ammo:WaitForChild("G36cAmmo"):FindFirstChild("AmmoText")

Is this in a localscript or a server script?

This script is a local script.

Would you be able to send a screenshot including where the localscript is located and the GUI?

Local script is within a tool in StarterPack and the GUI is in StarterGui within a folder called “Ammo”

Have you tried changing this line:
local textLabel = playerGui.Ammo:WaitForChild("G36cAmmo"):FindFirstChild("AmmoText")

to
local textLabel = playerGui:WaitForChild("Ammo"):WaitForChild("G36cAmmo"):FindFirstChild("AmmoText")?

Let me try that really quickly

It’s not good practice to have a chain of WaitForChild methods like this. Maybe split it up into multiple variables instead?