Hello, I've made a damage script in the past, and now I'm using it again. The damage script didn't have any debounce so I decided to add that, but then the script just broke entirely.
local debounce = false function OnTouch(damage) if not debounce then debounce = true damage.Parent:FindFirstChild("Humanoid").Health = damage.Parent:FindFirstChild("Humanoid").Health -50 wait(1) debounce = false end end script.Parent.Touched:connect(OnTouch)
(Damage script might look like a free model because I wasn't the best scripter back then)
Thanks for your time!
You need to check if the Humanoid really exists before attempting to change its health:
if damage.Parent:FindFirstChild("Humanoid") then damage.Parent:FindFirstChild("Humanoid").Health = damage.Parent:FindFirstChild("Humanoid").Health -50 end
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.