How to make a real assets loading bar?

Hello,

I’ve trying this for so long time and i still can’t find a clear good answer.

I’m trying to make a loading bar and a percentage that shows the actual assets that loaded.
I think the only thing i need is the amount assets need to be loaded and a function that loads them.

Could yo please help me?

Thank you for reading!

11 Likes

Hey,
What I’d suggest is using something such as

game:GetService('ContentProvider').RequestQueueSize

what this will do is send a request for the number of assets loading in the queue, which I think is what you’re looking for. Hopefully this helps, and below’s a quick link to the api reference for it.

6 Likes

Hello Choco_late,

Now i need to know the function that load all the assets (parts, decals, audio and such)

Thank you for helping!

1 Like

Use the ContentProvider:PreloadAsync() function.

1 Like

Hello DuckingDucky,

I’ve tried that but it doesn’t work.
I think it can only load roblox URL’s for sound and image ID’s.
When i use that to load parts and images and decals and such i get this error: Unable to cast to Array

Thank you for the reply!

1 Like

You should create a table with the objects (not id’s) you want to load.

local ContentProvider = game:GetService("ContentProvider")

local logoId = "rbxassetid://658743164"

local pageTurnId = "rbxassetid://12222076"

local part = Instance.new("Part")

local sound = Instance.new("Sound")

sound.SoundId = pageTurnId

local assets = { part, sound }

ContentProvider:PreloadAsync(assets)

print("All assets loaded.")

Or this:

local ContentProvider = game:GetService("ContentProvider")

local assets = game:GetDescendants()

ContentProvider:PreloadAsync(assets)

print("All assets loaded.")

Hello DuckingDucky,

You should better use game.Loaded:wait() but that’s not what i mean.
Your example waits until all assets are loaded wich is what i need but i want it to count every asset that loaded like a counter.

For example: 50/100 assets loaded (assets loaded/Total)

Thank you for the reply!

1 Like

Something like this?

3 Likes

Hello DuckingDucky,

That’s perfect!
That’s exactly what i need!

Thank you for helping!
How did you make it?

1 Like

Edit: Use my new gui

Hello, I didnt reply for so long because I was on another account. If you still need this then here is the script:

local ContentProvider = game:GetService("ContentProvider")

local toLoad = workspace -- Replace workspace with what you need to load
local assetsTable = toLoad:GetDescendants()
local totalAssets = #assetsTable
local assetsLoaded = 0

local Gui = script.Parent
local Bar = Gui:WaitForChild("Background"):WaitForChild("BarBackground"):WaitForChild("Bar")
local Text =  Gui:WaitForChild("Background"):WaitForChild("Text")
Gui.Enabled = true

for i = 1, totalAssets do
	pcall(function() -- You don't need pcall if you are not loading the whole game
		ContentProvider:PreloadAsync({assetsTable[i]})
		assetsLoaded = i
		Bar.Size = UDim2.new(i/totalAssets, 0, 1, 0)
		Text.Text = "Loading: " .. assetsTable[i].Name .. " ( " .. i .. " / " .. totalAssets .. " )"
		print(assetsLoaded)
	end)
end

Text.Text = "Loaded!"

wait(2)

Gui.Enabled = false

print("All assets loaded.")

Screenshot_26

22 Likes

In general, everything converges on the fact that you need to have a separate framework with all the necessary assets that you want to load (parts are not considered game assets, because they have already been loaded by the engine). It will be easier to create a folder inside ReplicatedStorage and use ContentProvider to load these assets.

I decided to make a better version of this. (@DuckingDucky is my old account).

Video:
https://i.gyazo.com/3fa8b6a55113d4216a7e718a63d1df9a.mp4

File:
LoadingGui.rbxm (9.8 KB)

8 Likes

Can I use this in my game? I’ll change how it looks. It is really nice, good work :slight_smile:

1 Like

I made it for everyone to use. :slightly_smiling_face:

2 Likes