Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How does the NPC's Health not glitch out?

Asked by 4 years ago

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

Log in to vote
1
Answered by 4 years ago

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)
0
I tried your code already before, it doesn't work. DindinYT37 246 — 4y
0
Try this instead: =< User#29913 36 — 4y
Ad
Log in to vote
1
Answered by
Syclya 224 Moderation Voter
4 years ago

You should look into HealthChanged as that was implemented for this purpose.

0
ok DindinYT37 246 — 4y

Answer this question