Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

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)

3 comments

0

How would I do the same with text buttons?

0

Simply change line 2, to script.Parent.MouseButton1Down

0

Did it for you

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.