# Checking if a humanoid's health is a certain percentage of it's maxhealth

So I’m making a skill where if an enemy’s health is 25% or lower of its MaxHealth then it instantly dies. However, I am unsure why it isnt working.

``````	hitbox.Touched:Connect(function(op)
if not op:IsDescendantOf(c) then
if op.Parent:FindFirstChild("Humanoid") then
if op.Parent:FindFirstChild("Humanoid").Health <= op.Parent:FindFirstChild("Humanoid").Health - (op.Parent:FindFirstChild("Humanoid").MaxHealth/4) then
op.Parent:FindFirstChild("Humanoid").Health = 0
print("w")
end
end
end
end)
``````

This should work.

``````	hitbox.Touched:Connect(function(op)
if not op:IsDescendantOf(c) then
if op.Parent:FindFirstChild("Humanoid") then
local Humanoid = op.Parent:FindFirstChild("Humanoid")

if Humanoid.Health <= Humanoid.MaxHealth /4 then
Humanoid.Health = 0
print("w")
end
end
end
end)
``````
2 Likes

thanks a lot!

[character limit]

You can use this trick for every linear percentage and portion calculation

``````MaxHealth ..... 100%
Health    ..... x%
x = Health * 100 / MaxHealth
``````

You get the percentage from this

E.g. MaxHealth = 250 and Health = 50

``````250 ...... 100%
50  ...... y%
y = 50 * 100 / 250 = 20
``````

So 50 is 20% of 250