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

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)
0
also, the first argument to OnServerEvent handlers is the player that fired the server.. so: `function(player, SoundID) .. end` User#23252 26 — 4y

2 answers

Log in to vote
1
Answered by 4 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.

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.

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

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

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

Answer this question