Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Audio won't play on remote event?

Asked by 5 years ago

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:

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

And in the brick

1game.ReplicatedStorage.Music.OnServerEvent:Connect(function(SoundID)
2    script.Parent.Sound.SoundId = "rbxassetid://"..SoundID
3    script.Parent.Sound:Play()
4end)
0
also, the first argument to OnServerEvent handlers is the player that fired the server.. so: `function(player, SoundID) .. end` User#23252 26 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

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.

1local function loadSound(sound)
2    -- Has the sound already loaded?
3    if not sound.IsLoaded then
4        -- if not, wait until it has been
5        sound.Loaded:Wait()
6    end
7end
8loadSound(Workspace.Sound)

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

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

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

Ad
Log in to vote
1
Answered by
Wiscript 622 Moderation Voter
5 years ago
Edited 5 years ago

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

You should try this:

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

For more info on this, check out this article

0
Also, ensure you use a valid Sound ID Wiscript 622 — 5y

Answer this question