Loading Screen with PreloadAysnc and RequestQueueSize

How am I suppose to do a loading assets screen with PreloadAsync and RequestQueueSize

I want to do something like #AssetsLoaded/#QueueSize for a percentage kind of deal.

I’m currently not using RequestQueueSize but using PreloadAsync. I would create multiple tables with one asset id and iterate through all the tables with PreloadAsync and incrementing a variable.

3 Likes

You will have to do something like:

local preloadAssets = {...}
local numPreloaded= 0
for _,asset in pairs(preloadAssets) do
    spawn(function()
        preloadAsync(asset)
        numPreloaded = numPreloaded + 1
        updateGui()
    end)
end

function updateGui()
    percentageComplete = numPreloaded/#preloadAssets
    percentageBar.Size = UDim2.new(percentageComplete, 0, _, _)
    if percentageComplete == 1 then
        removeLoadingScreen()
    end
end

You cannot use RequestQueueSize since it includes all assets being preloaded in the game – not just the ones you’ve explicitly preloaded.

6 Likes

You can also do this asynchronously considering it is going to schedule the preloads in the queue anyways.

Yeah this is currently what im doing

but each “asset” would be in its own separate table right?

Correct.

Im also getting a bunch of failed to preload in the output, how do i fix this?

PreloadAsync({asset})
Also use the actual in-game asset, not the url.
I typically get descendants of the whole game and add imagelabels and decals and etc. Either that or I tag them with Collection Service or store copies of them in a folder for easy preload access.

actual in game asset as in…?

The object itself, not a content url.


Its called contentIdList for whatever stupid reason bc its not a list of content Ids.

This makes more sense.

How do you stop the errors tho?

What exactly are the errors you are getting? We can’t do much with a simple ‘failed’.

If you haven’t already, try doing PreloadAsync({Asset}) instead of PreloadAsync(Asset). If that doesn’t work, make sure you using the Instances (actual objects) instead of the IDs. Those two things are what Wunder_Wulfe was suggesting.

If those don’t work, it could be an issue with the actual process of loading and unrelated to your code – or another issue, which is to do with the specific error.

Just do

spawn(function()
	game:GetService('ContentProvider'):PreloadAsync({game})
end)

that will do the trick,

unless you want to other assets to be loaded before other assets for something like an Intro Gui , Welcome Gui, Loading Screen, what ever you want to call it just Preload those things first.


This is what I currently have

-- At the very top
spawn(function()
	game:GetService('ContentProvider'):PreloadAsync({game:GetService('PlayerGui')})
end)

-- At the very bottom
-- Loading --
do
	local LoadingTxt = MG:WaitForChild('LoadingTxt')
	repeat LoadingTxt.Text = 'Loading ('..CP.RequestQueueSize..')' wait(1) until CP.RequestQueueSize <= 0
	wait(.5)
	LoadingTxt.TextColor3 = Colors.Green
	LoadingTxt.Text = 'Loading Complete'
	wait(.5)
	LoadingTxt:Destroy()
end

I don’t like Loading Screens so as a result I don’t add it to my game, instead I add an Indicator that tells the player exactly how many assets are there to load.

2 Likes

Are you sure it preloads all the descendant assets? It does not say anything about that on the wiki and it also shows separate objects with attached content. Also you can do this:

local f = function(t) contentProvider:PreloadAsync(t) end
local preload = function(t,...)
    local data = (...) and {t,...} or type(t)~="table" and {t} or t --table or tuple support
    coroutine.resume(coroutine.create(f),data)
end

And for loading separate things you can use a table like so:

local toLoad = {
    ["Main GUI"] = mygui,
    ["Game icons"] = iconstuff,
    Sounds = soundstuff
}

I would never recommend ever putting your entire game in the preload queue, let alone any top-level container. This is not necessarily what preload was made for. You’re really only supposed to be preloading assets you want your players to see immediately - your most important ones.


@Wunder_Wulfe

Yes it does.

Oh ok I must have not read that part lol

Yeah, I was doing that and it was taking God knows how long to finish.

Now i’m only loading in the assets you’re suppose to see/hear first.

1 Like