How do I check if the player got healed or got damaged?

Hello,
I’m making a quick health gui, It was boring without sounds so I tried attaching a damaged and a healed sound but I got stuck on How can I check if the player got healed or damaged, Any help is appreciated, Im currently using the health changed event.

2 Likes

Every time the player’s health changes, save that current health. I’m assuming this is a local script, so its as simple as creating a variable. Next time the health changes, check the current health against that stored health.

Psuedocode:

local lastHealth = 100 -- assuming your characters start with 100 health

Humanoid.HealthChanged:Connect(function(health)
     if health > lastHealth then
          -- player healed
     elseif < lastHealth then
          -- player took damage
     end
     lastHealth = health -- update value
end)
10 Likes

Will it affect it if I use the value inside of the property “MaxHealth” instead of 100?

1 Like

If you have a custom MaxHealth, instead of setting lastHealth to 100 when you initialize the script, you’d wanna set it to Humanoid.MaxHealth.

local lastHealth = Humanoid.MaxHealth

Then just do the rest of it as the previous poster had it.

EDIT

And if you ever change the MaxHealth before the player loses Health, you can do something like this:

Humanoid:GetPropertyChangedSignal(“MaxHealth”):Connect(function()
–Do your logic to change the maxhealth in here
end)

4 Likes