Detect player health percentage

Hello developers! I am currently writing a script and I want a HeartBeatSound sound to be heard when the humanoid is (example: 20% health). The question I have is how can I detect the player’s health percentage? I’ve looked everywhere but still can’t find it I’m trying to, I’d appreciate your help:slightly_smiling_face:

1 Like

Take the Humanoid’s Health and divide it by the Humanoid’s MaxHealth then multiply it by 100.


I’d also recommend rounding it as to not have a lot of extra numbers.


if (Hum.Health / Hum.MaxHealth * 100) then
print(“works! :D!”)

The result is 100 but, How can I make it 15%? pls help :sweat_smile:

Well, that’s when your health is at 15 out of 100.

So the modification would be:

if (Hum.Health / Hum.MaxHealth * 100) <= 15 then
print("i'm at 15% health or lower!")
1 Like

is not working :frowning:

local player = game.Players.LocalPlayer

local Hum = player.Character:WaitForChild("Humanoid")

if (Hum.Health / Hum.MaxHealth * 100) <= 15 then
	print("i'm at 15% health :D!")

The script is in StarterCharacterScripts .
15% of 100 is 15

You’ll have to check every time the Humanoid’s Health changes, otherwise that script will only fire once & won’t keep checking back for that if statement

You can use the Humanoid.HealthChanged Event for this, which fires whenever…The Humanoid’s Health changes (Whether it’s a positive or negative change)

local Player = game.Players.LocalPlayer
local Char = script.Parent --This is actually parented in your Character Model, so you could do that as well
local Humanoid = Char:WaitForChild("Humanoid")

local function DetectHealth(Health)
    if (Health / Humanoid.MaxHealth * 100) <= 15 then
        print("I'm at 15% Health! :D")


Thank you very much :slight_smile: .I am currently adding the sound I appreciate your help