Trying to get humanoid.health

Put this script in the workspace

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local HumHealth = char.Humanoid.Health
		if HumHealth <= 0 then
			print("Yeet")
		end
	end)
end)

Let me know if you have any problems or feedback.

as i said, the humanoid var is a humanoid, printing the health comfirms that. So everything u did is useless and actually the same what i did.

It doesn’t return a boolean, Humanoid.Health returns a number and you can’t convert booleans into numbers.

I knew that but the problem he has is quite something that I don’t usually see. I’m not certain myself if it’s actually a number value or booleans anymore. :sweat_smile:

Why not try the obvious and just use prints to confirm that you haven’t inadvertently changed a variable somewhere along the line? Just add the following before those lines run.

print(humanoid.Name, " : ", humanoid.Health )

2 Likes

Pls read the post carefully, I’ve already said, that this returns a number!

Does it change anything, that this is in a module script?

game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:Connect(function(char)
char:WaitForChild("Humanoid")
if char.humanoid.Health == 0 then
print("OOF")
end
end)
end)

Any comment?
I wrote, that i only want a “if” statement

I got it! Here is it:

First of all, I pasted this (server) script into StarterCharacterScripts:

local HealthValue = Instance.new("NumberValue")
HealthValue.Parent = script.Parent
HealthValue.Name = "HP"
HealthValue.Value = script.Parent.Humanoid.Health

script.Parent.Humanoid.HealthChanged:Connect(function(health)
    HealthValue.Value = health
end)

After that, I can easily access this value from another script (e. g.):

if game.Players[PlayerName].Character.HP.Value <= 0 then
print("You already oofed this player!")
end

Thanks for reading!

2 Likes