Loading screen when player joins

im making a loading screen to load in a few decals, can anyone tell me what im doing wrong for it to not show? this is local script inside the loading


game.Players.PlayerAdded:Connect(function(plr)
local Gui = script.Parent
	Gui.LoadingText.Visible = true
	Gui.Static1.Visible = true
	task.wait(5)
	Gui.Static2.Visible = true
	task.wait(5)
	Gui.Static3.Visible = true
	task.wait(5)
	Gui.LoadingText.Text = "ok loading is done now"
	task.wait(3)
	Gui.LoadingText:TweenPosition(UDim2.new(0.5, 0,1.5, 0),"In","Quad",2 ,true)
	task.wait(2)
	Gui.LoadingText:Destroy()
	Gui.Static1.Visible = false
	Gui.Static2.Visible = false
	Gui.Static3.Visible = false
	Gui.fart:Play()
end)

ps sorry for the messy code

The gui is created after the playermodel is made not before which means the function won’t detect the player joining.

oh then how could i fix this? should i add a wait

Yes, wait(0.5)

trying to add characters so i can actually send message

This is a joke, righ? Not trying to be rude, I am actually confused.

1 Like

This confuses me a little. But since you are going with player added and this script looks to be in the UI I just recommend not using a connection and putting this directly in so it runs immediately right once the script exists.

You should also use :WaitForChild(“Static2”) and the like which will look for it and wait until it exists to try changing it’s properties because it may not have loaded yet.

Make sure you can do this manually in your gui and it works (zindex needs to be correct)

Here is the corrected script (also make sure to uncheck the resetOnSpawn property for the screengui otherwise this will happen every time their character respawns

Gui.LoadingText.Visible = true
Gui:WaitForChild("Static1").Visible = true
task.wait(5)
Gui:WaitForChild("Static2").Visible = true
task.wait(5)
Gui:WaitForChild("Static3").Visible = true
task.wait(5)
Gui.LoadingText.Text = "ok loading is done now"
task.wait(3)
Gui.LoadingText:TweenPosition(UDim2.new(0.5, 0,1.5, 0),"In","Quad",2 ,true)
task.wait(2)
Gui.LoadingText:Destroy()
Gui.Static1.Visible = false
Gui.Static2.Visible = false
Gui.Static3.Visible = false
Gui.fart:Play()

if you’re making a loading screen, you should have a local script in ReplicatedFirst, and do everything from there

make sure you run:

repeat task.wait() until game:IsLoaded();

To ensure that the necessary assets are loaded before trying to access the GUI or anything needed for it. and do :WaitForChild() for every GUI you’re accessing or they may not exist yet.

Doing so on the playerAdded will cause some delay and not always load the screen first.

(p.s player added connections in local scripts aren’t necessary because a local script only starts existing once a new player is added)

Remove these lines, keep the rest.
Your script is in the PlayerGUI already, in a ScreenGui.

This is why it’s not running, but it could still use some WaitForChild()'s.