Loading screen that loads

So I am making a loading screen that says 100/493 assets loaded for example (No loading bar)

local num1
local num2

script.Parent.Text = num1…“/”…num2

Now, this would just put / because num1 and num2 do not equal anything, but how do I make it so they do equal something?

num1 = amount of assets that have loaded
num2 = full amount of assets in the game

What would I do?
I think num2 would equal game:getDescendants() (I think)
But how do I check how many assets have loaded?

3 Likes

I believe this is what you’re looking for

I would recommend using game:IsLoaded(). Here is the document to refer to

Also format your code!

So I have gotten this out of your posts:

local content = game:GetService("ContentProvider")

local num1 = content:PreloadAsync()
local num2 = game:GetDescendants()

so num 2 is how many desendants are in the game.
for instance, 2000.
and num 1 is how many assets, have loaded.
Correct me if I am wrong?

Edit: I get an error saying that num1 is nil.

1 Like

@Ineptxion

I think you do not get what I mean. Here is in simpler form:

How do I check how many assets are loaded

local num1 = -- How many assets are loaded in
1 Like

Num1 will always be nil because PreloadAsync() does not return anything. You also don’t need to use PreloadAsync() if you’re making a loading screen.

The Roblox API documentation has an example for loading screens.

Custom Loading Screens (roblox.com)

1 Like

PreloadAsync takes a table of asset URLs to load. In order to create a progress bar for it, you just need to create a for loop iterating over a table of asset URLs, and preload a table with each individual URL.

local assets = {
    "rbxassetid://1234",
    "rbxassetid://2345",
    ...etc
}

for index, url in ipairs(assets) do
    ContentProvider:PreloadAsync({ url })
    Progress.Text = string.format("%d/%d", index, #assets)
end

I usually create a ModuleScript containing a table of assets URLs I need preloaded so I can easily update it if needed.

I have lots of experience with this.
I for example in my game Helsinki Vantaa i have a custom loading screen to ensure that no assets are missing.
So first you have a LocalScript in ReplicatedFirst which creates the GUI.
Then you wait for the local player to appear and then call

Players.LocalPlayer:WaitForChild("PlayerGui")

And then AND ONLY THEN you can remove the default Roblox loading screen with

ReplicatedFirst:RemoveDefaultLoadingScreen()

and parent your own GUI in to the Player Gui.

Now you cannot instantly just display the loading amount it has loaded because the ContentProvider service(the service which loads content) does not know the amount it has to load because it has not loaded that info either. So

You first must display “Loading game structure…”
Then you run this.

if not game:IsLoaded() then
	game.Loaded:Wait()
end

What this ^ basically does is that it checks if the game structure has loaded.

Then you must check if the character has loaded.
Insert this \ / function in your script.

local function waitForCharacterLoaded()
	if Players.CharacterAutoLoads then
		local localPlayer = Players.LocalPlayer
		if not localPlayer then
			Players:GetPropertyChangedSignal("LocalPlayer"):wait()
			localPlayer = Players.LocalPlayer
		end
		if not localPlayer.Character then
			localPlayer.CharacterAdded:wait()
		end
	end
end

Then display this message “Loading characters …”
and call
waitForCharacterLoaded()

Now we have loaded all the necessary assets so you could add a “Skip” loading screen button.
Now you probably would still wan’t to make a loading screen for the unnecessary assets.
And here you can display the percentage loaded.
So you first store the max amount of assets being loaded via doing.

local MaxAssets = ContentProvider.RequestQueueSize

And then just start the loading process.
So first display the message “Loading assets …”
And then do \ /

repeat
	local CurrentLoaded = ContentProvider.RequestQueueSize / MaxAssets
	local PercentLoaded = math.round(CurrentLoaded * 100)
	-- // Your other code
	wait(1.4)
until ContentProvider.RequestQueueSize < 5

And there you go all assets have loaded.
If you wan’t to preload some assets you can do as @cxmeels suggested. But remember to wrap ContentProvider:PreloadAsync() in a pcall or xpcall.

You can additionally do stuff like failed asset detection but this was a kind of a bare bones guide to a good loading screen.

8 Likes

I do not think you guys have read the post, I DO NOT, want a loading bar.
All I need is num1/num2.

So basically, all I need is to tell me what num1 would be (How many assets have already loaded.

1 Like

The loading of assets is not that simple. But if you absolutely need to known it is ContentProvider.RequestQueueSize.

But please read my post there are lots of other stuff you need to take care off during loading like game:IsLoaded() and character loading before you can get the value of RequestQueueSize to be accurate.

But keep in mind you absolutely should do the game structure loading and character loading before any other stuff! If you don’t you cannot get an accurate amount of assets loaded! (The reading from RequestQueueSize will be bigger than the initial amount causing stuff like 1432/9 assets loaded when it infact should be 1432/1521 assets loaded)

And num2 is not game:GetDescendants(). It is ContentProvider.RequestQueueSize

I made the first number:

local content = game:GetService("ContentProvider")

local num1 = content.RequestQueueSize

Though it just says that num1 = 0.

Does this mean:
Its loaded 0 assets?
It has 0 assets left to load?

No. This just says the start number of assets loading. You would have to get that number when the game starts and then minus the current amount from it.

Also be sure to first do game:IsLoaded() and character loading to get an accurate amount of assets in the queue.

Can I just refer you back to my post?

You need to manually specify the asset URLs you want preloaded in a table and loop through each item. There’s no point waiting for the game and player to load because by that point they have probably already loaded.

This code snippet I provided is exactly what you asked. It will display loaded items / total items as you requested.