OK so I'm making a door that's locked and it plays a sound when you touch it, but when you touch it once it plays the sound multiple times.
1 | Music = script.Sound |
2 | script.Parent.Touched:connect( function (hit) |
3 | Music:Play() |
4 | wait( 5.5 ) |
5 | Music:Stop() |
6 | end ) |
You'd use what is called a "debounce"
01 | Music = script.Sound |
02 | local debounce = false |
03 | script.Parent.Touched:connect( function (hit) |
04 | if debounce = = false then --if debounce is false |
05 | debounce = true --Sets it to true |
06 | Music:Play() |
07 | wait( 5.5 ) |
08 | debounce = false --turns it back to false |
09 | Music:Stop() |
10 |
11 | end |
12 | end ) |