Trying to get

Hey, I got a problem: I’m trying to “if statement” the health of a humanoid so my code is:
if humanoid.Health <= 0 then
and this error comes out:
“ReplicatedStorage.WeaponsSystem.WeaponsSystem:445: attempt to compare boolean and number”

Thx for helping out!

Your script itself seems fine. The error though, isn’t. A boolean value has only two values, these being “true”, and “false”. Is that the entire script?

1 Like

No it’s not, because the error is on line 445. Could I ask what the variable humanoid is from? It seems you are trying to ask a boolean value if it is less that 0, which is a number.

Could you give us some more code to work with here?

Your current script is checking if the health is less than 0. Invert the > to <. Also, the error is from something else.

replace if humanoid.Health <= 0 then
to if humanoid.Health <1 then

You could just do something like

1 Like

Some of you asked about the use of it:

  • You can trust me! This is a cut from the line 445 and around, you dont need more!
  • The “humanoid” variable is confirmed, that its a humanoid cuz some script before says: “humanoid:TakeDamage(50)”
  • No, I didnt forget the direction of the < and > I want to prove, if the character is getting shot, when its already dead.


  • As I already mentioned, this is in a Weapons System, basically this script is in a function, which is getting fired when a character gets shot.
  • I’m making stats about it, eg.: Damage dealt: 2 345
  • I’m trying to fix a bug with this: when you shoot a dead body, this dood which shoots the character collects “Damage dealt” points

That doesnt care, the script is a cut out of a longer script.
Or do u want the whole 500 lines script?

What’s your variable for humanoid… still.

A humanoid, bruh!

I mentioned that in my reply a sec ago

It is all you need, the rest is just other stuff…

Right then, well, (somewhere) in the script, you are asking a boolean value if it has a value, simple answer, it doesn’t. A boolean value only has two values: true and false.

We’re under the impression that your humanoid variable is a little messed up due to this error.

1 Like

ok: I tried to print the humanoid.Health value: it gives me a number

Since it prints out a boolean-ish? number why not convert it into a real number instead.

if tonumber(humanoid.Health) <= 0 then

Thats a great idea! But it still gives me the same error :frowning:

May I see what’s wrong with the code? Maybe just the output. This errors seems pretty new to me and I’m unsure of how to fix it properly.

20:41:01.115 - ReplicatedStorage.WeaponsSystem.WeaponsSystem:442: attempt to compare boolean and number

Could you try printing this?

print(humanoid.Health, type(humanoid.Health))

I already tried printing but i havent tried this “type” thing yet
Ill do that