Waiting for sounds loaded

I don’t think I can get away with WaitForChild when it comes to sounds.
So I have a folder and eventually a folder with subfolders that will contain descendant sounds throughout, and I want to know, be assured, that the sounds are loaded in when they are about to be used.

How do I wait for a sound loaded en masse? Should I just connect events to every single sound for its loaded state entry event and then hook a counter up that lets the rest of the script continue once the number equals the number of sounds?

You could use repeat wait() until sound.Loaded == true

But you can also use PreloadAsync which is a bit more complicated, info on that here.

local ContentProvider = game:GetService("ContentProvider")
ContentProvider:PreloadAsync({Sound.SoundId},nil)  --no process error function

--rest of code yeilding to

The above code is just failing to load, and, testing in Studio the sound does indeed load afterwards. It is called Preload, but it does not appear to prioritize load. On the wiki it almost seems as if it just gives you an event to connect to for when something failed to load for that very moment. Correct me if I’m wrong.

Thanks for the link, but note that my question concerned multiple sounds, and not a single sound like your first solution, for which case is not scalable.

I might take a look at this later instead: What is the best way to preload all assets? - #4 by RuizuKun_Dev

Consider looking into a useful function of RBXScriptSignals called Wait()

You could iterate over each sound, creating one and setting them to each ID until they have loaded
If you’re wondering how you’d achieve this: Sound.Loaded:Wait()

This will yield the code until the Loaded event is fired.

Is this not related to the gross nature of a general wait()? I have intentionally stayed away from these because of the mental association of playing laggy games that use wait(time).

RBXScriptSignal:Wait() and wait() are not the same function

One holds the code until an event fires, and the latter holds the code for a specified amount of time (but not very reliably)

local c = LocalPlayer.CharacterAdded:Wait()

U need ro give it the Sound Object. Not the Sound Id, for multiple sounds but the other sounds into the table

I just used an example from the Roblox Developer site to preload the audio modules and to handle playing:

It works very well and is easily customised.

1 Like

Too late but, I just using for that:

sound.Loaded:Connect(function()
       -- code
end)

Or:

sound.Loaded:Wait()

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.