Checking to see what percentage of the game finished loading?

Hello

I’m trying to make a loading script that shows how much percent of the game finished loading, in different categories, like UI, Buildings, Scripts, etc.

Is there a way to do that?
Thanks!

1 Like

You can use the RequestQueueSize property of ContentProvider to create a loading bar.

The documentation recommends not to use it, but it does give a code sample of the proper way to use it.

local ContentProvider = game:GetService("ContentProvider")
local Players = game:GetService("Players")
 
-- create a screenGui
local localPlayer = Players.LocalPlayer
local playerGui = localPlayer:WaitForChild("PlayerGui")
local screenGui = Instance.new("ScreenGui", playerGui)
 
-- create a basic loading bar
local frame = Instance.new("Frame", screenGui)
frame.Size = UDim2.new(0.5, 0, 0.1, 0)
frame.Position = UDim2.new(0.5, 0, 0.5, 0)
frame.AnchorPoint = Vector2.new(0.5, 0.5)
 
local bar = Instance.new("Frame", frame)
bar.Size = UDim2.new(0, 0, 1, 0)
bar.Position = UDim2.new(0, 0, 0, 0)
bar.BackgroundColor3 = Color3.new(0, 0, 1)
 
-- create some sample assets
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://301964312"
local sound2 = Instance.new("Sound")
sound2.SoundId = "rbxassetid://301964312"
 
-- create a table of assets to be loaded
local assets = {
	sound,
	sound2
}
 
wait(3)
 
for i = 1, #assets do
	local asset = assets[i]
	ContentProvider:PreloadAsync({asset}) -- 1 at a time, yields
	local progress = i / #assets
	bar.Size = UDim2.new(progress, 0, 1, 0)
end
 
print("loading done")
3 Likes

For the percentage, there is a formula.

Instead of using RequestQueueSize, you can just use PreloadAsync() to preload any chosen assets.

The formula to get the percentage would be:

loaded_assets / max_assets * 100

So if we combine this altogether we get:

local assets = workspace:GetChildren(); --not a good idea, just an example
local ContentProvider = game:GetService("ContentProvider");

load_percentage = 0

local amount_loaded = 0;

for i = 1, #assets do
    ContentProvider:PreloadAsync({assets[i]});
    amount_loaded = i;
    load_percentage = (amount_loaded / #assets) * 100;
end
3 Likes

Doesn’t the game automatically replicate everything in workspace, startergui, starterplayer, etc to client? Does using PreloadAsync() on those things make a difference?

Thx a lot!