So I began rewriting the preloading system that my game has since :Preload() is now deprecated. The only issue I ran into was that RequestQueueSize will only return 1 if you use :PreloadAsync() and pass in a table of instances as you should.
I was wondering if there was an easier way to bypass this issue instead of iterating through the table and passing in one instance at a time or using IsLoaded on every asset in the table. If there was a way to retrieve how many items in the table still have to be preloaded that would make this so much easier.
local gui = game.Players.LocalPlayer.PlayerGui
local CP = game:GetService("ContentProvider")
local assets = {}
script.Parent:RemoveDefaultLoadingScreen()
script.Loading:Clone().Parent = gui
spawn(function()
while wait() do
if gui:FindFirstChild("Loading") ~= nil then
gui.Loading.Number.Text = math.ceil((#assets - CP.RequestQueueSize)/#assets * 100).."%"
end
if CP.RequestQueueSize == 0 then
wait(.2)
if gui:FindFirstChild("Loading") ~= nil then
gui.Loading:Destroy()
break
end
end
end
end)
function Preload()
local function iterate(v)
for _, x in pairs(v:GetChildren()) do
if x:IsA("Sound") or x:IsA("ImageLabel") or x:IsA("ImageButton") then
table.insert(assets, x)
end
iterate(x)
end
end
iterate(workspace)
iterate(game.StarterGui)
iterate(game.ReplicatedStorage)
CP:PreloadAsync(assets)
end
Preload()