Well, I tried to make a game with NPC's, it works sofar but if you do more damage than the NPC's MaxHealth the NPC's Health goes into negative and doesn't respawn.
Here's the Code I tried to fix it with:
local hum = script.Parent.Humanoid hum.Health.Changed:Connect(function(health) if hum.Health < 0 then hum.Health = hum.MaxHealth - hum.MaxHealth end end)
Thanks in Advance - DindinYT37
So, basically there is an error in the code because you didn't add a '=' sign after the '<'.
Your code:
local hum = script.Parent.Humanoid hum.Health.Changed:Connect(function(health) if hum.Health < 0 then hum.Health = hum.MaxHealth - hum.MaxHealth end end)
My code:
local hum = script.Parent.Humanoid hum.Health.Changed:Connect(function(health) if hum.Health <= 0 then hum.Health = hum.MaxHealth - hum.MaxHealth end end)
You should look into HealthChanged as that was implemented for this purpose.