Loading sound "efficiently" for slow connections?

Straight to the point – Usually sound(s) are loaded with assets when a player joins a game: in this case, I have a music GUI where you have to interact with textbuttons to play the specified sound.

Is there any good ways to optimize and make it so the sounds (only) start to load when you click on a textbutton? I’m not necessarily a good scripter – But would a possible solution be to make it so when you click on the textbutton, it creates a new instance of a sound object instead of having it preloaded already?

Thanks,

2 Likes

By preloading an asset simply pushes the asset to the top of the download queue so that it is the first asset the client downloads. With that being said, only preload assets that need to be preloaded. In your case, if you want the sound to be played as soon as you click the button without any delays, I recommend preloading it.

To preload assets you need to use the ContentProvider service by Roblox. It is mainly used to preload assets in your game. We will also need to use the PreloadAsync() method associated with ContentProvider to preload the assets.

Basic example:

local ContentProviderService = game:GetService("ContentProvider")

local Assets = script.Assets -- The folder containing all the assets you want to preload

print("Preloading assets...")

ContentProviderService:PreloadAsync(Assets:GetChildren()) -- Preloads all the assets inside the folder

print("Assets loaded!")

If you would like to read up more on the ContentProvider service, here is the link to the documentation page: ContentProvider | Roblox Creator Documentation

I hope this helps.

2 Likes

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