How would i check if a Humanoid Took Damage and how much he took?

The title says it all lol :rofl:

Use Humanoid | Roblox Creator Documentation and variables.

You’ll need to compare the last known health with the current health to do so. There is an example on the page I linked. Additionally you’ll likely need to consider health regeneration.

1 Like

You can use the HealthChanged event in the humanoid you want to check if they took damage and do something. An example would be this taking into account health regeneration

local hum = script.Parent.Humanoid
local curhp = hum.Health

hum.HealthChanged:Connect(function(newhp)
	if curhp < newhp then return end --new hp greater than curren, nothing
	local difference = math.abs(curhp - newhp)
	print(difference)
	curhp = newhp
end)

If the humanoid with this script took damage, it’ll check if the current health is less than the new health and if it is, do nothing. And then get the difference and print it and then set the current health to the new health

Edit: Example @cloakedyoshi provided had math.abs() so I think that’s needed as well.

@Tunnells You can check the difference variable and do something based o nthat

local hum = script.Parent.Humanoid
local curhp = hum.Health

hum.HealthChanged:Connect(function(newhp)
	if curhp < newhp then return end --new hp greater than current, do nothing if so
	local difference = math.abs(curhp - newhp)
	print(difference)
	if difference >= 40 then
		--Do something
	end
	curhp = newhp
end)
3 Likes

I mean lets say if a npc takes 40 damage, it would ragdoll him but if it took 10 it wouldnt

so basically you want a ragdoll script?

no i was giving a example lol i want too do something else

Read my edit on my first reply, it’ll provide you with what you could do to do something if the damage taken was equal to or greater than a specific number

2 Likes

Thank you so much :slight_smile:

1 Like

Anytime! If you have anymore issues don’t be afraid to make another post!