How to detect when you get damaged

how to detect when you get damaged and how much damage you took plssss
hi thanks thx hi
ermmmmmmmmm thats all I want to know

1 Like
local localPlayer = game.Players.LocalPlayer
local char = localPlayer.Character

char.Humanoid.Health.HealthChanged:Connect(function()
    if char.Humanoid.Health < 100 then
        - - whatever you want to do here
2 Likes

ummmmmmmmmm does that function return amount of damage taken? it ok

Did you test it, did it work. Sorry if it doesn’t I might’ve used the wrong event

ermmmmm it says DamageDealt is not a valid member of humanoid im just tested it

1 Like

I edited it, see if it works now
@bluehalf66660000, are you there?

for some reason the code below only works when the character dies (im tested it by slowly using :TakeDamage

Another edit, let me know if it works
Sorry, just changed the operator

Another edit!

sorry it took a while but it still has the same problem

I get an error saying attempt to index number with “healthchanged”

Not a very efficient way to do it, but you could use a formula to calculate it.

You could use this to calculate the damage taken:

local damageTaken = (char.Humanoid.MaxHealth - char.Humanoid.Health)

It’s Health.Changed! I’m so sorry, I’m losing it

1 Like

ok im get error attempt to index number with ‘Changed’

Try this code:

local Players = game:GetService("Players")
local LPlayer = Players.LocalPlayer
local character = game.Workspace:WaitForChild(LPlayer.Name) or LPlayer.Character or LPlayer.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")

wait(1)

Humanoid.Health.HealthChanged:Connect(function(health)
    if Humaoind.Health < 100 then
        - - whatever you want to do here

Full script would look like this:

local Players = game:GetSerivce("Players")

local localPlayer = Players.LocalPlayer
local char = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")

humanoid:GetPropertyChangedSignal("Health"):Connect(function()
    if humanoid.Health < 100 then
        local damageTaken = (humanoid.MaxHealth - humanoid.Health)
        --Whatever you want to run goes here
    end
end)

for some reason this only runs the code below when the character diesss (im teseted this using :TakeDamage())


this me trying it and it nottee work

Why can’t you determine the damage taken from the script that takes the damage? …

umm im making a game where multiple things attack me!!! (pvp game) and im too lazy to add that to all characterr so im ask how to check when damaged within the character im using

Instead of “<” it should be “<=” otherwise this script won’t work.

local Players = game:GetSerivce("Players")

local localPlayer = Players.LocalPlayer
local char = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")

humanoid:GetPropertyChangedSignal("Health"):Connect(function()
    if humanoid.Health <= 99 then
        local damageTaken = (humanoid.MaxHealth - humanoid.Health)
        --Whatever you want to run goes here
    end
end)