How to make a loading screen fast?

Hey guys! I was wondering if someone can help me to make my custom loading screen to be faster. Now it will take around 10 minutes to load, for a relative small game. This is my code:

local ContentProvider = game:GetService("ContentProvider")

local toLoad = workspace
local assetsTable = toLoad:GetDescendants()
local totalAssets = #assetsTable
local assetsLoaded = 0

local Gui = script.Parent
local PercentText = Gui:WaitForChild("Frame"):WaitForChild("PercentageProgress")
Gui.Enabled = true

for _,v in pairs(assetsTable) do
	ContentProvider:PreloadAsync({v})
	assetsLoaded += 1
	PercentText.Text = tostring(math.floor((assetsLoaded/totalAssets)*100)) .. "%"
end

repeat
	wait()
until
script.Parent.Frame.Done.Value == true

wait(1)
script.Parent.Enabled = false

Thanks for reading (and replying)!

dont loop this

game:GetService("ContentProvider"):PreloadAsync(toLoad:GetDescendants())
1 Like

Adding on to what @Qin2007 said, use a single PreloadAsync function and wrap it in a task.spawn() so that it will run in a different thread.

Example:

task.spawn(function()
  ContentProvider:PreloadAsync(something:GetChildren())
end)
2 Likes

Thanks for your reply! But how would I then display the percentage that is loaded?

Then I’m changing my question: “How could I make a good loading screen?”

Just make a simple loading screen, that is what I would say.

But I want an advanced loading screen xD

Then I guess you could use a loading loop animation instead of showing the percentage?

Like this:

Yeah, but I tried your code and it still takes 8 minutes to load

I know had this code:

local ContentProvider = game:GetService("ContentProvider")

local toLoad = workspace
local assetsTable = toLoad:GetDescendants()
local totalAssets = #assetsTable
local assetsLoaded = 0

local Gui = script.Parent
local PercentText = Gui:WaitForChild("Frame"):WaitForChild("PercentageProgress")
Gui.Enabled = true

task.spawn(function()
	ContentProvider:PreloadAsync(assetsTable)
end)

repeat
	wait()
until
script.Parent.Frame.Done.Value == true

wait(1)
script.Parent.Enabled = false

Why are you loading the whole workspace? Just load the folder where you place all the assets in.

1 Like

But I need to wait before everything in the workspace is loaded, right? Every model, etc.

That is not necessary, just load the assets that are in ReplicatedStorage or ReplicatedFirst.

1 Like

Why should you load asssets from the ReplicatedStorage?

do

local ContentProvider = game:GetService("ContentProvider")
ContentProvider:PreloadAsync(toLoad function()
    -- show here it
end)

Preloading the workspace is unnecessary and takes more time to preload.

Ah Okay, thank you! I know have this:

local ContentProvider = game:GetService("ContentProvider")

local toLoad = game.ReplicatedStorage
local assetsTable = toLoad:GetDescendants()
local totalAssets = #assetsTable
local assetsLoaded = 0

local Gui = script.Parent
local PercentText = Gui:WaitForChild("Frame"):WaitForChild("PercentageProgress")
Gui.Enabled = true

for _,v in pairs(assetsTable) do
	ContentProvider:PreloadAsync(assetsTable)
	assetsLoaded += 1
	PercentText.Text = tostring(math.floor((assetsLoaded/totalAssets)*100)) .. "%"
end
repeat
	wait()
until
script.Parent.Frame.Done.Value == true

wait(1)
script.Parent.Enabled = false

That loads pretty fast! :slight_smile:

Thanks for your help!

1 Like