How to prevent the UI from coming up after player resets?

Hi! I am trying to make a loading screen, but with the current script I have that shows it when a player is added to the game, it shows when players reset too. I’d expect many people to have already made threads about this but I couldn’t find any with the right solution. Currently, I just have this;

game.Players.PlayerAdded:Connect(function(plr)
game.StarterGui.JoinUI.MainBG.Visible = true
end)

But, I just want it to show when a player joins, how would I do that?

4 Likes

Try using a local script for your loading and put it in ReplicatedFirst, alongside a ScreenGui with ResetOnSpawn set to false with your loading GUI in :slightly_smiling_face:

edit: if you want to wait for the server to be ready when you use this method, you can use a remote function that the client can invoke. On the server, this function would yield until the player is ready (or just return immediately if they’re already ready). That way, after you’ve invoked that function from the loading script, you know that the player is ready and can proceed to hide/destroy/tween out the loading GUI.

3 Likes

This is a problem I couldn’t figure out for months back when I started: StarterGui just holds the template for the player’s interface, not the actual player’s interface. When you change it, you’re just changing the template that gets placed in the user’s PlayerGui when they respawn. Like @Elttob said, try having a template located in ReplicatedFirst (so it’s still accessible from the client) and using a client-side script to copy it to the player’s interface (located at player.PlayerGui) .

An example (localscript inside of game.StarterPlayer.StarterPlayerScripts):

local intro=game.ReplicatedFirst.Intro:Clone()
intro.MainBG.Visible=true
intro.Parent=game.Players.LocalPlayer.PlayerGui

Here’s the file if you want to see it in action:
IntroExample.rbxl (17.5 KB)

It’s also worth noting that you can’t change a client’s UI elements from the server, only from that client.

4 Likes