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.
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.
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
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.")
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)
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.")
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.