I need a player to be able to click a block, and then it plays audio. How do I do this?
✓ ANSWER ACCEPTED
How do I make audio play when a player clicks a block (using clickdetectors)?
3 answers
✓ Accepted answer
a = false
script.Parent.ClickDetector.MouseClick:connect(function(player)
if a == false then
game.Workspace.Audio:Play()
a = true
else
game.Workspace.Audio:Stop()
a = false
end
end)
@Capin, I'll help you out with that.
a = false
script.Parent.ClickDetector.MouseClick:connect(function(player)
if a == false then
game.Workspace.Audio:Play()
a = true
else
game.Workspace.Audio:Stop()
a = false
end
end)
For TextButtons:
a = false
script.Parent.MouseButton1Down:connect(function(player)
if a == false then
game.Workspace.Audio:Play()
a = true
else
game.Workspace.Audio:Stop()
a = false
end
end)
script.Parent.ClickDetector.MouseClick:connect(function(player)
game.Workspace.Audio:Play()
end)
This is assuming the script is in the part, and the audio is called Audio, you can change it accordingly.
1 comment
0
Thank you, this works great! But could you add 1 more thing to it? Is there a way that I could make it so when you click again, it stops?
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
How would I do the same with text buttons?
Simply change line 2, to
script.Parent.MouseButton1DownDid it for you