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:
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.
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.