1 | function 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 |
8 | end |
9 | 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?
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:
1 | function 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 |
8 | end |
9 | game.Workspace.Part.ClickDetector.MouseClick:connect(onclick) |
He is correct. You need the prefix for your sound Id. But you could also make your code a bit simpler.
1 | function 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 |
8 | end |
9 | 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.