I need help my sound in my script wont play so I want to preload it so it can play. I was wondering if you know any advice you could give me on this topic?
When you preload a sound, you have to use the ContentProvider service from Roblox in a LocalScript.
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:
local ContentProvider = game:GetService("ContentProvider") local PreloadItems = { Sound1, Sound2, etc } 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:
local ContentProvider = game:GetService("ContentProvider") local PreloadItems = workspace.PreloadItems:GetChildren() 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.
local ContentProvider = game:GetService("ContentProvider") local PreloadItems = workspace.PreloadItems:GetChildren() ContentProvider:PreloadAsync(PreloadItems) while ContentProvider.RequestQueueSize > 0 do wait() end print("Done preload!")
My guess is that you should use WaitForChild.
local sound = script:WaitForChild("Sound")