How do I load my screengui before anything else?

When I load into my game, I see the baseplate and everything being loaded for a split second until my loading screen pops up.

I’ve tried to prevent this using this piece of code:

local plrgui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
plrgui.SetTopbarTransparency(0)

local gui = script.ScreenGui:Clone()
gui.Parent = plrgui

repeat until game:IsLoaded()

gui.Enabled = false

which didn’t work and instead just made my game crash.

Is there something wrong with the code and is there a better way of preventing this from happening?

Put it in ReplicatedFirst.

I have done that already

charrrrrrrrrr

local PlayerGUI = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
repeat wait() until game:IsLoaded()