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