Answered by
5 years ago Edited 5 years ago
You're not using debounce properly. When you use debounce, you check to see if it's false. If it is, on the very next line, set it to true, so it can't be fired multiple times in a span of a few seconds.
01 | Lava.Touched:Connect( function (findPlayer) |
02 | if findPlayer.Parent:FindFirstChild( "Humanoid" ) and debounce = = false then |
06 | findPlayer.Parent:FindFirstChild( "Humanoid" ).Health = 0 |
07 | CurrentAlive.Value = CurrentAlive.Value - 1 |
11 | print 'debounce = true, not false' |
You're supposed to set debounce back to false at the end so code can be ran again. It was only working once because it only runs if debounce is false, and at the end, you set it to true and didn't modify it any further, which prevented it from running more than once.
I believe the reason the CurrentAlive value is going into the negatives is because this event listener is firing regardless of the Humanoid's health. You only want to remove one value from CurrentAlive when someone actually dies, not when a body part touches the lava.
01 | Lava.Touched:Connect( function (findPlayer) |
02 | if findPlayer.Parent:FindFirstChild( "Humanoid" ) and debounce = = false then |
06 | local Humanoid = findPlayer.Parent:FindFirstChild( 'Humanoid' ) |
07 | if Humanoid and Humanoid.Health ~ = 0 then |
08 | findPlayer.Parent:FindFirstChild( "Humanoid" ).Health = 0 |
09 | CurrentAlive.Value = CurrentAlive.Value - 1 |
14 | print 'debounce = true, not false' |
This section of code has been modified to make debounce work properly, and to only subtract 1 from CurrentAlive if the Player is touching this lava for the first time.
Now, there's a problem. If I'm not mistaken, you're trying to use a debounce to prevent the CurrentAlive value from subtracting more than 1 for 1 death. But at the same time, you're preventing other players from dying.
1 | Lava.Touched:Connect( function (Hit) |
2 | local Humanoid = Hit.Parent:FindFirstChild( 'Humanoid' ) |
4 | if Humanoid.Health ~ = 0 then |
6 | CurrentAlive.Value = CurrentAlive.Value - 1 |
There's the revised code. If I understand what you're trying to do, this should do it.