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

How can I properly chain together these two things without getting an error?

Asked by 3 years ago
Edited 3 years ago

I made a screenGui that lets you input a sound ID and then just hit the "Play" button to play a sound on a speaker I have in the workspace, but the value isn't chaining together or something else. I'm getting the following error: "Failed to load sound rbxassetid://: Unable to download sound data (x2)".

Here's my code

local btn = script.Parent
local playSound = Instance.new('Sound')
local speaker = game.Workspace.SPEAKER


btn.MouseButton1Down:Connect(function()
    playSound.Parent = speaker
    playSound.Volume = 1
    playSound.RollOffMaxDistance = 200
    playSound.RollOffMinDistance = 20
    playSound.Looped = false
    playSound.Playing = true
    playSound.SoundId = "rbxassetid://".. tostring(script.Parent.Parent.TextBox.Text)

end)

I'm guessing the error is where I'm chaining the "rbxassetid://" and input value for the Id together? This is a server script btw, I want this to be a server script so the submitted sound Id's are server-sided.

1 answer

Log in to vote
1
Answered by
cancle5 120
3 years ago
Edited 3 years ago

Basically, it doesnt work since you don't have a sound id. You can upload one or just take a free one.

I remade the code here it is.

local btn = script.Parent
local playSound = Instance.new('Sound')
local speaker = game.Workspace.SPEAKER


btn.MouseButton1Down:Connect(function()
    playSound.Parent = speaker
    playSound.Volume = 1
    playSound.RollOffMaxDistance = 200
    playSound.RollOffMinDistance = 20
    playSound.Looped = false
    playSound.Playing = true
    playSound.SoundId = script.Parent.Parent.TextBox.Text
    playSound:Play()
end)

Also if i would make it i would try to make it abit dif...

You dont have to make a new Sound. You could just change the properties and just play it.

Btw if you want the whole server to hear it you should use a event.

EDIT: I made a game with everything fully working https://web.roblox.com/games/6574707256/Untitled-Game-SoundGui

1
Oooooh Ok. That makes more sense. And thank you for the example game! Voltaicmimic 43 — 3y
Ad

Answer this question