Using PreloadAsync for load screen?

I added a load screen to my game that displays the asset count as they load. I noticed that usually play testing in studio loads extremely fast since everything is technically already loaded. But when I add the load screen, the loading slows down to what it would have been if I was playing normally, so I was starting to wonder if PreloadAsync is the right tool to use for this load screen when its clearly loading things that have already been loaded in studio. And if using PreloadAsync for this is bad practice then what should I use instead?

Code (In StarterGui) :

local ContentProvider = game:GetService("ContentProvider")
local TweenServ = game:GetService("TweenService")
local plr = game:GetService("Players").LocalPlayer

local loadScreen = script.Parent.Parent
local loadFrame = script.Parent
local loadBG = loadFrame:WaitForChild("LoadBG")
local loadBar = loadBG:WaitForChild("LoadBar")
local assetCount = loadFrame:WaitForChild("AssetCount")

RepFirst:RemoveDefaultLoadingScreen()

local toLoad = game
local assetsTable = toLoad:GetDescendants()
local totalAssets = #assetsTable

local assetsLoaded = 0

loadBar.Size = UDim2.fromScale(0,1)
loadScreen.Enabled = true

for asset = 1, totalAssets do
	
	pcall(function()
		
		ContentProvider:PreloadAsync({assetsTable[asset]})
		assetsLoaded = asset
		
		local destination = {Size = UDim2.fromScale(asset / totalAssets, 1)}
		local tweenInfo = TweenInfo.new(.3, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
		
		local barTween = TweenServ:Create(loadBar, tweenInfo, destination)
		barTween:Play()
		
		assetCount.Text = asset.." / "..totalAssets
		
	end)
end

loadScreen.Enabled = false

Please, don’t EVER preload everything in the whole game. Seriously, just preload stuff that actually needs to be preloaded, such as meshes that are seen once you join.

What you’re doing is actually downloading EVERY SINGLE asset in your game, you’re not waiting for the game to load. What this means is that instead of you letting the game load over time (only assets having to load getting loaded and that), you load the whole game, which can take a very long time, depending on player’s WiFi and your game size.

Instead of his, have a loop that checks the asset loading queue.

while task.wait(0.1) and ContentProvider.AssetQueue > 0 do
    -- code
end
2 Likes