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
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!”)
end
The result is 100 but, How can I make it 15%? pls help
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!")
end
is not working
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!")
end
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")
end
end
Humanoid.HealthChanged:Connect(DetectHealth)
Thank you very much .I am currently adding the sound I appreciate your help