Can somebody help me add in a wait? When I touch the brick, the sound play and it work but I don't want someone to just keep touching the brick over and over without waiting for a second or so to make the sound play again. It also lag too and I don't know why...
1 | script.Parent.Touched:connect( function () |
2 | script.Parent.Sound:Play() |
3 | end ) |
This is simple. We're just going to make a bool variable
, and if the variable is true, then we play the sound and make the variable false, wait a while, and make it true again.
Example,
1 | local Debounce = true |
2 | script.Parent.Touched:connect( function () |
3 | if Debounce then |
4 | Debounce = false |
5 | script.Parent.Sound:Play() |
6 | wait( 5 ) -- Wait As long as you want |
7 | Deounce = true |
8 | end |
9 | end ) |
Good Luck!