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?
Assuming you have a part named Button in workspace, and a valid sound named Sound in workspace, this should work:
1 | local debounce = false |
2 | game.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 |
9 | end ) |
You need: A Sound in Workspace (Call it aSound) a script in the part.
1 | debounce = true |
2 | script.Parent.Touched:connect( function () |
3 | if debounce = = true then |
4 | debounce = false |
5 | workspace.aSound:Play() |
6 | debounce = true |
7 | end |
8 | end ) |