Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Audio won't play on remote event?

I'm making a GUI where when you type text into a textbox then press "Play" it will play that audio in a brick but it doesn't seem to be working. Im getting the error:

Failed to load sound rbxassetid://blarfart: Unable to download sound data (x2)

and

Here is the script inside of the button:

script.Parent.MouseButton1Click:Connect(function()
	local SoundID = script.Parent.Parent.Music.Text
	game.ReplicatedStorage.Music:FireServer(SoundID)
end)

And in the brick

game.ReplicatedStorage.Music.OnServerEvent:Connect(function(SoundID)
	script.Parent.Sound.SoundId = "rbxassetid://"..SoundID
	script.Parent.Sound:Play()
end)

1 comment

0

also, the first argument to OnServerEvent handlers is the player that fired the server.. so: function(player, SoundID) .. end

2 answers

✓ Accepted answer

You might want to wait the script until the sound is actually loaded from Roblox's Servers, that's probably the issue you're facing. You can use Sound.IsLoaded for this. The example used by Roblox is below, you can read more about it here.

local function loadSound(sound)
	-- Has the sound already loaded?
	if not sound.IsLoaded then 
		-- if not, wait until it has been
		sound.Loaded:Wait()
	end
end
loadSound(Workspace.Sound)

In your instance, I'd implement it like what I have below.

game.ReplicatedStorage.Music.OnServerEvent:Connect(function(SoundID)
	script.Parent.Sound.SoundId = "rbxassetid://"..SoundID
	if script.Parent.Sound.IsLoaded then
		script.Parent.Sound:Play()
	end
end)

Hope that helps, consider accepting this answer if it helps at all. If not, comment and I'll be sure to assist you further.

This is probably because you're not allowing the audio to load first.

You should try this:

game.ReplicatedStorage.Music.OnServerEvent:Connect(function(SoundID)
    script.Parent.Sound.SoundId = string.format("rbxassetid://%i+", SoundID)
    if not script.Parent.Sound:IsLoaded() then
         script.Parent.Sound.Loaded:Wait() 
    end-- this will yield until loaded
    script.Parent.Sound:Play() -- now play
end)

For more info on this, check out this article

1 comment

0

Also, ensure you use a valid Sound ID

This discussion is preserved as it was. New answers, comments, and votes are closed.