Loading Screen Reloads when Players Respawn

Hi developers! I have stumbled upon a problem and have found no solutions! Hope you can help. (Sorry if this is messy, this is my first post!)

What I’m Doing

I’ve been making a simple GUI loading screen.
The actual loading script works fine! Here is my script:

wait(1) -- Let things load in

script.Parent.Enabled = true

local Loading = script.Parent.Loading
local Back = Loading.Back
local Front = Loading.Front
local Player = game.Players.LocalPlayer
repeat wait() until Player.Character
local WA = {} -- WA = Workspace Amount

Front.Size = UDim2.new(0,0,1,0)
Front.BackgroundColor3 = Color3.new(25/255,25/255,25/255)

local function Scan(this)
	for i, v in pairs(this:GetDescendants()) do
		table.insert(WA, v)
	end
end
local Service = {
"Lighting",
"InsertService",
"ContentProvider",
"CollectionService",
"RunService",
"SoundService",
"BadgeService",
"Selection",
"GuiService",
"UserInputService",
"Debris",
"TeleportService",
"Chat",
"PhysicsService",
"AssetService"
}
for i=0, #Service, 1 do
	game:GetService(tostring(Service[i]))
end

Scan(game.Players)
Scan(game.StarterGui)

for i=0, #Service, 1 do
	if game:GetService(tostring(Service[i])) ~= nil then
		Scan(game:GetService(tostring(Service[i])))
	end
end

for i=0, #WA, 1 do
	Front.Size = UDim2.new(i/#WA+0.055, 0, 1, 0)
	if WA[i] ~= nil then
		Loading.Text = "   Loading: " .. tostring(WA[i])
	end
	wait(0.04)
end
Loading.Text = "   Loading: Completed."
script.Parent.BG.Done.Visible = true

local function RGB(r,g,b)
	return Color3.new(r/255,g/255,b/255)
end
local Color = Front.BackgroundColor3

for i=Color.r, 15, -1 do
	Front.ImageColor3 = RGB(i,i,i)
	wait(0.07)
end
wait()
for i=15, 25, 1 do
	Front.ImageColor3 = RGB(i,i,i)
	wait(0.05)
end

Problem 1

I have 2 problems! One my problems are that the UI comes up again every single time you spawn in. Here is the script used to load the UI for the player.

local loadgui = script.loadingGUI:Clone()
game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:wait()
	loadgui:Clone().Parent = player.PlayerGui
end)

I also guess I should show you what it looks like in the explorer…
image

Problem 2

It takes WAY too long! It loads so many individual objects!

Have I actually Tried to fix it?

Yes. I looked around YT and the DevForum and found nothing which helped me with the situation.

Thanks for reading everyone! If you could reply some help I would love that! I’m VERY new to scripting so sorry if I sound like a noob…

Edit 1: Just correcting a part a said twice by accident
Edit 2: Problem 1 was solved!

1 Like

Just so you know in the top right it says someone else’s name because I asked my friend to record it for me (we are doing a group project of me and him)

1 Like

This code should solve it, try it.

1 Like

Ok, thanks! I’ll try it now! I’m pretty new. Thanks for responding!

1 Like

ScreenGUI’s have a property called “Reset on Spawn”, its turned on by default, if you uncheck it in the respective ScreenGUI properties the gui will not reset everytime the player spawns.

3 Likes

Problem is @hellomehappy1_Create is cloning it instead using it in starter gui

I actually already did that.
image

I think the problem was when the player respawned which resulted in the player getting it once they are readded to game.Players

You could probably make it add the player into a table and it only does the loading screen if the player is not inside the table OR put an item inside the Player/His Character upon joining to use in knowing if he just joined or respawned.

what Luke said works fine though, I am not great with scripting tbh so what your saying seems a bit complicated.

Uhh it kinda stopped working. Which script should I have put that in?