Best way to load sounds properly?

I’m currently having a game called Even more FNF, The game is a rythm type of game which really depend on the musics. But I have one big problem:

Loading time is long / Some assets refuse to load if fail once.

Since I’ve open the game to mobile and tablet. I’m regularly having people complaining about not loading properly. I’ve been trying to find an efficient way to load without annoying the users by preloading the needed songs before a play is perform. My current method is the following:

BASSETS = {}
local Max, Cur = 0, 0
for _,v in pairs(Songs) do
	if v:IsA("Sound") then
		Max = Max + 1
		if not v.IsLoaded then
			table.insert(BASSETS, v.SoundId)

			-- Trying to load the sound by playing it silently
			local l = v:Clone()
			l.Parent = game.Players.LocalPlayer.PlayerGui.MainGui
			l.Volume = 0
			l:Play()
			game.Debris:AddItem(l, 1)
		else
			Cur = Cur + 1
		end
	end
end

if #BASSETS == 0 then
	break
end

game.Players.LocalPlayer.PlayerGui.MainGui.LoadingSong.TxtData.Text = "Downloading data... (" .. Cur .. " / " .. Max ..  ")"
game:GetService("ContentProvider"):PreloadAsync(BASSETS)

If you can download the sound for the first time. The game doesn’t preload the songs anymore. But if it fail, It will never be able to load the sounds for some reason (The upper code is in a loop)


What it look like for someone that can’t load a particular music

1 Like

Bump, I’m still having this issue. Any help will be greatly appreciated !

1 Like

I’m pretty sure you are using it wrong

https://developer.roblox.com/en-us/api-reference/function/ContentProvider/PreloadAsync

Try passing in an array of Instances instead of an array of AssetIDs

In the example, It also use the asset ID. It should work that way but I’ll try out and see If I see anymore changes.
chrome_lh9fqi36K7

“If any of the assets fail to load, an error message appears in the output. The method itself will not error and it will continue executing until it has processed each requested instance or asset ID.”

This is what it says in the documentation, even if an error is thrown it will still work (presumably)