So, I'm creating a zombie NPC that damages a player on touch and the script worked perfectly fine until I decided to add a debounce to it. The script still works, however, the script works inside any part that isn't inside a NPC. Once it's placed inside a part inside a NPC it won't work. I don't understand, someone please help!
debounce = false
script.Parent.Touched:connect(function(hit)
h = hit.Parent:FindFirstChild("Humanoid")
if debounce == false then
debounce = true
h.Health = h.Health - 50
wait(2)
debounce = false
end
end)

3 comments
Make sure to check that the 'hit' has a Humanoid, because if it touches an accessory, the script world break, since it wouldn't be able to find a humanoid in the accessory.
The torso or whatever this script is inside of is most likely hitting the other parts of the NPC, causing the debounce to go off.
Do you know how I could fix that?