Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How does the NPC's Health not glitch out?

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

2 answers

✓ Accepted answer

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)

2 comments

0

I tried your code already before, it doesn't work.

0

Try this instead: =<

This discussion is preserved as it was. New answers, comments, and votes are closed.