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

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

Asked by 10 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 6 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 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 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? SchonATL 15 — 10y
0
Simply change line 2, to `script.Parent.MouseButton1Down` Shawnyg 4330 — 10y
0
Did it for you Shawnyg 4330 — 10y
Log in to vote
0
Answered by 10 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? SchonATL 15 — 10y

Answer this question