The different types of for loops:
You can use for loops to go through all the objects. You can either use numeric loops (for i = 1,10 do) or generic loops (for i,v in pairs(TABLE) do) to accomplish this.
Let's assume your sound library is in ServerStorage in a Model called SLibrary, we would either of the following pieces of code to get all the children.
Generic For:
for i,v in pairs(game.ServerStorage.SLibrary:GetChildren()) do
end
Numeric For:
local library = game.ServerStorage.SLibrary:GetChildren()
for i = 1, #library do
end
Preloading the sound:
Now to preload, we would do the following:
Generic For:
for i,sound in pairs(game.ServerStorage.SLibrary:GetChildren()) do
if sound:IsA("Sound") then
game:GetService("ContentProvider"):Preload(sound.SoundId)
end
end
Numeric For:
local library = game.ServerStorage.SLibrary:GetChildren()
for i = 1, #library do
if library[i]:IsA("Sound") then
game:GetService("ContentProvider"):Preload(library[i].SoundId)
end
end
The two pieces of code above are similar in some ways and different in others. It is important to notice these differences for when you use for loops in the future.
That should give you an idea of what to do, I hope this helped.
3 comments
I like how I get a negative rating for just not knowing something. 10/10 website.
Granted, I can learn tables and such with the wiki, preloading is very unclear, and I've gotten no help with it.
You'll get that sometimes. I believe that asking to know how to do something is okay.