Hello devs, i wonder if its possible to make anti NaN health, because here’s a way to make enemy in my game have inf health which makes him impossible to kill. Script i made:
myHuman.HealthChanged:Connect(function(hp)
if myHuman.Health==“nan” or myHuman.Health==“inf” then
myHuman.Health=myHuman.MaxHealth
end
if myHuman.Health>myHuman.MaxHealth then
myHuman.Health=myHuman.MaxHealth
end
if myHuman.Health<0 then
myHuman.Health=0
end
end)
Some background: NaN is weird. Nothing is equal to NaN, not even NaN itself. In this case, as suggested by the first reply, you’d need to compare the health with itself to check for NaN. It could look like this:
if myHuman.Health ~= myHuman.Health then
Additionally, you don’t need to compare with infinity because this is already covered by the condition myHuman.Health > myHuman.MaxHealth.
faster isn’t always better, take your time when replying