Help with loading screen length

I have a loading GUI script in ReplicatedFirst that grabs a bunch of objects then loads them with ContentProvider:PreloadAsync() but the issue is (I think) it always gets stuck on adding all these assets into the toLoad table with the WaitForChild functions. This leads to extremely long loading times.

How would I fix this issue with long loading times and still actually load assets?

local toLoad = {
	assets = {},
	images = {},
	sounds = {}
}
for i, v in pairs(workspace:WaitForChild("ServerRef"):WaitForChild("Lobby"):GetDescendants()) do
	if v:IsA("UnionOperation") or v:IsA("MeshPart") then
		table.insert(toLoad.assets, #toLoad.assets + 1, v)
	end
end
for i, v in pairs(workspace:WaitForChild("ServerRef"):WaitForChild("Lobby"):GetDescendants()) do
	if v:IsA("ImageLabel") or v:IsA("ImageButton") or v:IsA("Decal") then
		table.insert(toLoad.images, #toLoad.images + 1, v)
	end
end
for i, v in pairs(PlayerGui:WaitForChild("MainGameGuis"):GetDescendants()) do
	if v:IsA("ImageLabel") or v:IsA("ImageButton") then
		table.insert(toLoad.images, #toLoad.images + 1, v)
	end
end
for i, v in pairs(game.SoundService.ClientSounds:GetChildren()) do
	if v:IsA("Sound") then
		table.insert(toLoad.sounds, #toLoad.sounds + 1, v)
	end
end

Load in chunks maybe? I don’t know if that will help but it might. Somehow you need to compensate for the waiting. Perhaps have a function that works on waiting and grabbing children and then when one comes in pass it along to be stored in the table. Idk hope that helps a bit. :smiley:

Could you elaborate on your idea? I’m having a hard time understanding what you mean.

So, you have these loops, each loop is checking and waiting for objects. Right now your waiting till each loop finishes waiting for objects. You could run each loop in a coroutine, this would allow them to run at the same time each time one finishes waiting for an object, have it pass that object into your array. You could then load the array of objects after so many elements. Loading w/e is ready at the time and repeating.

1 Like

That helped speeding it up but I think the long loading times comes from the initial WaitForChilds for ServerRef and the game’s guis. Not really sure how to go about getting those to load in faster.

Maybe try to use something like: local sucess,message = pcall(function())
– ContentProvider:PreloadAsync()
end) – (I might of spelled something wrong

The loading works fine without any errors - the problem is how long it takes to load and it’s due to the preloading of the assets seen in the first post.

Did you implement the partial/chunk loading as well? That part was meant to try and compensate for the waitForChilds. Also in the other scripts check for what has loaded and make things available as they come in as opposed to waiting for everything at once.

1 Like

I took some data with the default robox loading screen, the new version of my loading screen that uses coroutines with the WaitForChilds, and the old one that did the WaitForChilds one after another. Generally, it seems that the loading time has gone down to around the default loading screen, so thanks for the help!

default roblox loading screen:
23
29
23
27
29

new custom loading screen:
21
27
25
29
32

old custom loading screen:
31
23
31
38
39

(in seconds)

EDIT: I forgot to include the averages, so here:

default roblox loading screen:
26.2 seconds

new custom loading screen:
26.8 seconds

old custom loading screen:
32.4 seconds
1 Like

Awesome! Glad I could help. :smiley:

1 Like