Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
2

How do I make audio play when a player clicks a block (using clickdetectors)?

Asked by 6 years ago

I need a player to be able to click a block, and then it plays audio. How do I do this?

3 answers

Log in to vote
1
Answered by 2 years ago
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)
Ad
Log in to vote
1
Answered by
Shawnyg 4241 Trusted Badge of Merit Snack Break Moderation Voter Administrator Community Moderator Super Administrator
6 years ago

@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)

0
How would I do the same with text buttons? capinbuilda 15 — 6y
0
Simply change line 2, to `script.Parent.MouseButton1Down` Shawnyg 4241 — 6y
0
Did it for you Shawnyg 4241 — 6y
Log in to vote
0
Answered by 6 years ago
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.

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? capinbuilda 15 — 6y

Answer this question