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)
debounce = false for i, v in pairs(script.Parent:GetChildren()) do if v.ClassName == "Part" then v.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local h = hit.Parent:FindFirstChild("Humanoid") if debounce == false then debounce = true h.Health = h.Health - 50 wait(2) debounce = false end end end) end end
Put that script inside of the NPC