I'm having trouble with a certain script. I don't know how to stop a sound from playing multiple times when you touch a brick. It keeps repeating and I have no answer for this.
This is the whole script v
01 | local Part = script.Parent |
02 | local Sound 1 = script.Parent.Sound 1 |
03 |
04 |
05 | Part.Touched:connect( function (hit) |
06 | local hum = hit.Parent:WaitForChild( 'Humanoid' ) |
07 | if hum then |
08 | while true do |
09 | Sound 1 :Play() |
10 | wait( 1 ) |
11 | --wait(0.82800000000000007) |
12 | break |
13 | end |
14 |
15 | end |
16 | end ) |
p.s I'm new to scripting, so go easy on me.
Once upon a time, there was debounce. Debounce is used to help in these types of situations, by stopping an event from firing multiple times.
01 | local Part = script.Parent |
02 | local Sound 1 = script.Parent.Sound 1 |
03 | local deb = false |
04 |
05 |
06 | Part.Touched:connect( function (hit) |
07 | local hum = hit.Parent:WaitForChild( 'Humanoid' ) |
08 | if hum and deb = = false then |
09 | deb = true |
10 | Sound 1 :Play() |
11 | wait( 1 ) |
12 | deb = false |
13 | Sound 1 :Stop() |
14 | end |
15 | end ) |
You also had an unnecessary while loop.