So I made this loading screen, and for some reason it is slow. The game normally takes only like 7 seconds to load or so. However, this loading screen only deletes itself once it has counted all of the assets. Is there a way to make this faster?
local ContentProvider = game:GetService("ContentProvider")
repeat wait() until game:IsLoaded()
local player = game.Players.LocalPlayer
local Ui = player.PlayerGui
local loadingUi = script:WaitForChild("LoadingGui"):Clone()
loadingUi.Parent = Ui
local Parts = game:GetDescendants()
local Allparts = #Parts
wait(1)
for i, part in Parts do
ContentProvider:PreloadAsync({part})
loadingUi.Frame.Loading.Text = i.."/"..Allparts
end
loadingUi:Destroy()
Looks like it’s work just as you have instructed it to work. No need to preload the entire game…
local Parts = game:GetDescendants()
for i, part in Parts do
That’s every single thing in the game, even the default set up.
If you want to preload your Gui just focus on that.
I don’t know how this gets mistaken so so so so many times but ContentProvider is NOT for instances, it loads asset id’s!
You can use WaitForChild() to wait for models to load.
Also here’s a code example on how you could wait for assets to load:
local maxLoadTime = 5
local totalDescendants = 10
------
local folder = workspace:WaitForChild("PartsToLoad")
local startTime = os.time()
local checkup = function ()
if #folder:GetDescendants() == totalDescendants or os.time() >= startTime + maxLoadTime then
-- loading screen stuff
end
end
folder.DescendantAdded:Connect(checkup)
What this does is check until there’s a specific amount of descendants in a folder (of course u’d need to modify that) and for lower end devices that can’t load everything in it will automatically continue if it hasn’T loaded in after 5 seconds.
Note that I wasn’t able to test this code also u should only put neccessary parts in that folder because if you put all parts into it it will just always wait the 5 seconds because you simply cannot load everything at once.
Run this code on your command bar to check how many descendants a folder has:
local folder = workspace.Folder print(#folder:GetDescendants)