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

Why won't this sound play when I click this brick?

Asked by
EpicLilC 150
9 years ago
function onclick(Player)
    local Part = game.Workspace.Part
    Instance.new("Sound",Part)
    game.Workspace.Part.Sound.SoundId= "274504661"
    game.Workspace.Part.Sound:Play()
    game.Workspace.Part.Sound.Looped = true
    game.Workspace.Part.Sound.Volume = 1
end
game.Workspace.Part.ClickDetector.MouseClick:connect(onclick)

It keeps saying sound failed to load. Also, how would I make it so you can only click the brick once and then it stops letting the player click it?

2 answers

Log in to vote
3
Answered by 9 years ago

When entering a sound ID, you need either rbxassetid:// or http://www.roblox.com/asset?id= as a prefix of the ID. Your code would need to be:

function onclick(Player)
    local Part = game.Workspace.Part
    Instance.new("Sound",Part)
    game.Workspace.Part.Sound.SoundId= "rbxassetid://274504661" -- Added the prefix
    game.Workspace.Part.Sound:Play()
    game.Workspace.Part.Sound.Looped = true
    game.Workspace.Part.Sound.Volume = 1
end
game.Workspace.Part.ClickDetector.MouseClick:connect(onclick)

Ad
Log in to vote
1
Answered by 9 years ago

He is correct. You need the prefix for your sound Id. But you could also make your code a bit simpler.


function onclick(Player) local Part = game.Workspace.Part Instance.new("Sound",Part) game.Workspace.Part.Sound.SoundId= "rbxassetid://274504661" Part.Sound:Play() Part.Sound.Looped = true Part.Sound.Volume = 1 end game.Workspace.Part.ClickDetector.MouseClick:connect(onclick)

You can get rid of the game.workspace because you locally defined Part as being at game.workspace so it will refer to your localized location and know that Part is in game.workspace.

Answer this question