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

How do I make a sound play when a certain part is touched?

Asked by 10 years ago

I'm trying to figure out how to make a sound play when a certain part is touched. I tried before but it never played.Can someone please type in a script for me?

2 answers

Log in to vote
1
Answered by
MrFlimsy 345 Moderation Voter
10 years ago

Assuming you have a part named Button in workspace, and a valid sound named Sound in workspace, this should work:

1local debounce = false
2game.Workspace.Button.Touched:connect(function(hit)
3    if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
4        debounce = true
5        game.Workspace.Sound:Play()
6        wait(1.5)
7        debounce = false
8    end
9end)
0
Thanks! I'll try it and change the button and sound to what I used in the game. flamenathan327 20 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

You need: A Sound in Workspace (Call it aSound) a script in the part.

1debounce = true
2script.Parent.Touched:connect(function ()
3if debounce == true then
4debounce = false
5workspace.aSound:Play()
6debounce = true
7end
8end)
0
Thanks! If that other guy's script doesn't work then I'll use this one. flamenathan327 20 — 10y
0
K fahmisack123 385 — 10y

Answer this question