Why is my loading screen so slow?

So I made this loading screen, and for some reason it is slow. The game normally takes only like 7 seconds to load or so. However, this loading screen only deletes itself once it has counted all of the assets. Is there a way to make this faster?

local ContentProvider = game:GetService("ContentProvider")

repeat wait() until game:IsLoaded()

local player = game.Players.LocalPlayer
local Ui = player.PlayerGui

local loadingUi = script:WaitForChild("LoadingGui"):Clone()
loadingUi.Parent = Ui

local Parts = game:GetDescendants()
local Allparts = #Parts

wait(1)

for i, part in Parts do
	ContentProvider:PreloadAsync({part})
	loadingUi.Frame.Loading.Text = i.."/"..Allparts
end

loadingUi:Destroy()

remove the amount of parts to load or just load the parts closest to the playe/ the parts thats acutally needed

1 Like

Something I’ve seen make it go faster is excluding folders and models, i have some ideas why but nothings conclusive.
Try adding

If part:IsA("Model") or part:IsA("Folder") then continue end

At the beginning of the loop

Looks like it’s work just as you have instructed it to work. No need to preload the entire game…
local Parts = game:GetDescendants()
for i, part in Parts do

That’s every single thing in the game, even the default set up.
If you want to preload your Gui just focus on that.

I don’t know how this gets mistaken so so so so many times but ContentProvider is NOT for instances, it loads asset id’s!
You can use WaitForChild() to wait for models to load.

Official example code from the ContentProvider documentary:

local ContentProvider = game:GetService("ContentProvider")

local LOGO_ID = "rbxassetid://658743164"
local PAGE_TURN_ID = "rbxassetid://12222076"

local decal = Instance.new("Decal")
decal.Texture = LOGO_ID

local sound = Instance.new("Sound")
sound.SoundId = PAGE_TURN_ID

local assets = { decal, sound }

ContentProvider:PreloadAsync(assets)

print("All assets loaded.")

(Edits: Formatting and grammar fixes)

1 Like

Also here’s a code example on how you could wait for assets to load:

local maxLoadTime = 5
local totalDescendants = 10

------
local folder = workspace:WaitForChild("PartsToLoad")
local startTime = os.time()

local checkup = function ()
	if #folder:GetDescendants() == totalDescendants or os.time() >= startTime + maxLoadTime then
		-- loading screen stuff
	end
end

folder.DescendantAdded:Connect(checkup)

What this does is check until there’s a specific amount of descendants in a folder (of course u’d need to modify that) and for lower end devices that can’t load everything in it will automatically continue if it hasn’T loaded in after 5 seconds.

Note that I wasn’t able to test this code also u should only put neccessary parts in that folder because if you put all parts into it it will just always wait the 5 seconds because you simply cannot load everything at once.

Run this code on your command bar to check how many descendants a folder has:

local folder = workspace.Folder print(#folder:GetDescendants)
1 Like

Since this relates to loading the game, StreamingEnabled might be involved. Try to see if there are any differences with it on and off.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.