local function getAssets()
local assets = {}
for k, v in pairs(ROOTS) do
for k, v in pairs(v:GetDescendants()) do
if v:IsA("Decal") or v:IsA("ParticleEmitter") or v:IsA("Texture") then
table.insert(assets, v.Texture)
elseif v:IsA("ImageButton") or v:IsA("ImageLabel") then
table.insert(assets, v.Image)
elseif v:IsA("Sound") then
table.insert(assets, v.SoundId)
end
end
end
return assets
end
This feels wrong. Is there a better way. May not support future instances and there’s probably instances I’m missing, so bad code
This function is only called once, I just wanted a better method to collect the assets instead of checking what type of class it is, instead just finding Content properties and adding them to the table
I don’t know if thats possible or if it is how to do it
Don’t preload everything at once - everyone loses that way. Players get long meaningless load times and you have to write something that preloads EVERYTHING, adding a skip button only increases the chance that nothing important will preload. Preload what the player will see in the first minute or so of gameplay.
Edit: Just to be clear though, you should only preload assets that actually need to be preloaded (if you are preventing the player from playing until all that stuff is loaded). If it’s just preloading in the background & you aren’t holding up the user, then it’s fine. It’s marked as an “async” function, which basically means it runs asynchronously from the main thread, thus won’t slow any other scripts down.
ROOTS is a collection of folders with assets that are required immediately.
I’m fully aware it’s asynchronous and I’m preloading everything in ROOTS for good reason.