Answered by
6 years ago Edited 6 years ago
You need to check if the Humanoid really exists before attempting to change its health:
1 | if damage.Parent:FindFirstChild( "Humanoid" ) then |
2 | damage.Parent:FindFirstChild( "Humanoid" ).Health = damage.Parent:FindFirstChild( "Humanoid" ).Health - 50 |
If you don't, then everytime the Humanoid doesn't exist, the Health property won't exist too, so you get the error "attempt to index a nil value".
As for debounce breaking your script, you only "turn off" debounce after you deal the damage, and since the error stops the function's execution, it ends up never finishing it
Besides that, your script looks fine to me (and actually works). Just make sure to use Tab when indenting. And as someone pointed out in the comments, connect is deprecated, use Connect.