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 9 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
9 years ago

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

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

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

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

Answer this question