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
1function onclick(Player)
2    local Part = game.Workspace.Part
3    Instance.new("Sound",Part)
4    game.Workspace.Part.Sound.SoundId= "274504661"
5    game.Workspace.Part.Sound:Play()
6    game.Workspace.Part.Sound.Looped = true
7    game.Workspace.Part.Sound.Volume = 1
8end
9game.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:

1function onclick(Player)
2    local Part = game.Workspace.Part
3    Instance.new("Sound",Part)
4    game.Workspace.Part.Sound.SoundId= "rbxassetid://274504661" -- Added the prefix
5    game.Workspace.Part.Sound:Play()
6    game.Workspace.Part.Sound.Looped = true
7    game.Workspace.Part.Sound.Volume = 1
8end
9game.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.

1function onclick(Player)
2    local Part = game.Workspace.Part
3    Instance.new("Sound",Part)
4    game.Workspace.Part.Sound.SoundId= "rbxassetid://274504661"
5    Part.Sound:Play()
6    Part.Sound.Looped = true
7    Part.Sound.Volume = 1
8end
9game.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