How to reload music?

I’m making a game that runs 3 music at the same time. However, with a half chance, one of the three musics failes to load, resulting in an error.

Piano.Loaded:Wait()
Drum.Loaded:Wait()
Voice.Loaded:Wait()
Piano:Play()
Drum:Play()
Voice:Play()

Failed to load sound rbxassetid://blablabla: Unable to download sound data

Rejoining until all three are loaded is too inefficient.
how to make music reload?

Instance:WaitForChild is your best bet. It waits until they load and then moves to the next line.
It should work fine since you wait until each loads and after they all load that’s when you are playing all 3 at the same time with these lines:

Piano:Play()
Drum:Play()
Voice:Play()
1 Like

It is unnecessary to wait until it is loaded because it can’t be loaded.
I have to try loading the music again.

What you can just do is simply error catching on each through protected calling. For the most part this will stop your code from completely not working, however you do have to be prepared to handle the error, this can easily be looped recursively however I would not suggest this (when you read about the error below you’ll understand) as it could result in an infinite loop.

About the error itself:

The error itself is usually caused on Roblox’s end, unless you provide an invalid asset as the sound itself. Usually it clears up after it has been a while, as Roblox’s API can be slightly temperamental and its likely not a fault of your own if you can fully confirm that you have done nothing to warrant such an error. If it doesn’t clear up after a few days, it might be best to test your code on sounds which you can confirm work and see if its an issue with your code or the sound itself.

Example of error catching in lua from the Roblox API Documentation:

local function fireWeapon()
	if not weaponEquipped then
		error("No weapon equipped!")
	end
	-- Proceed...
end
 
local success, errorMessage = pcall(fireWeapon)
if not success then
	print(errorMessage)
end 

So how can you solve this?

If you do want to recursively do it then the following code should work and prevent a recursion error adapting from the above:

local function PlaySound()
	-- play sound stuff here, do it 1 sound at a time
end
 
local success, errorMessage
while not success do -- doing it like this prevents a recursion depth error, if we kept making it call itself every time we failed we'd get a recursion depth error.
	local success, errorMessage = pcall(PlaySound)
	if not success then -- if it failed then actually print the message
		print(errorMessage)
	end
end 
-- if we get to here, then the sound played with no issue

-- note:  if you do want to be cautious 100% make sure that after maybe 3 attempts it gives up else you'll be infinitely looping.

You stated that half the time it fails to download, not every time in your first post.

You are only using wait(), which is 1/30th of a second, before you move to the next line of code. If the sound doesn’t load by the time you try to Play it, then of course it will error.
Just try using WaitForChild to see if that clears up your issue. That will wait until the Sound loads, then move on to the rest of the code.

And as @Clu said, it may be a Roblox error, not yours.

it print no error message even it did not loaded.

i put sound:Play() on PlaySound()