When you preload a sound, you have to use the ContentProvider service from Roblox in a LocalScript.
1 | local ContentProvider = game:GetService( "ContentProvider" ) |
Then, you use the ContentProvider's function PreloadAsync to preload all assets that are in a table that you pass into the function like so:
1 | local ContentProvider = game:GetService( "ContentProvider" ) |
7 | ContentProvider:PreloadAsync(PreloadItems) |
The way that the PreloadAsync works is that the table of items must be Objects in the workspace. For instance, when you want to preload a sound, you need a Sound Object in the workspace or in a folder in the workspace. What I like to do is have a Folder named "PreloadObjects" in the workspace filled with the sounds that I need to preload. Then you can access all of them into a table as a :GetChildren() table like so:
1 | local ContentProvider = game:GetService( "ContentProvider" ) |
2 | local PreloadItems = workspace.PreloadItems:GetChildren() |
3 | ContentProvider:PreloadAsync(PreloadItems) |
If you want to see a visual of how your queue of preloaded assets are going, you can view them with ContentProvider.RequestQueueSize.
1 | local ContentProvider = game:GetService( "ContentProvider" ) |
2 | local PreloadItems = workspace.PreloadItems:GetChildren() |
3 | ContentProvider:PreloadAsync(PreloadItems) |
4 | while ContentProvider.RequestQueueSize > 0 do wait() end |