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.
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.
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.
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.
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.
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:
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.