Is there a way to detect over damage?

So I have a bunch of guns in my game and some of them are one shot weapon, I was wondering if there’s a way to detect over damage, like doing more damage than needed. (ex: Someone is at 30 health and you shoot them with a gun that do 100 damage, that does 70 damage more than needed)
This way I had an idea of maybe making the ragdoll comically flies away if you do 10 damage more than needed, I got the fling part to work but I don’t know how can I detect the over damage.
Now I could probably do this by doing a bit of math in the gun, but I have a lot of gun in my game and I was wondering if there’s a quick way to do this with the humanoid itself?

If playerA takes damage of greater value than their health, then the resulting number will be negative. Use that to your advantage.

local overdmg = playerA.Humanoid.Health - dmg

Edit: You’d have to calculate that before actually subtracting the damage from the player’s health, though. And you may also want to process the number a little bit beforehand just to make the number a bit more logical.

overdmg = Math.abs(Math.min(0, overdmg))
1 Like

You could simply check if (the target’s HP- GunDamage) > 0 ,

if it is, take all damage.

If not, take him the remaining hp, for e.g, if he has 34 hp, take him 34 hp and not 100.

2 Likes

Now both of this work but because there’s a lot of guns in my game I’d have to go through every script to implement this so I can get the gun damage value, I was wondering if there’s a way to check how much damage was taken with the humanoid itself and not inside every gun. (Also some gun like shotgun would be hard to detect as each pellet from the shotgun do small damage and doesn’t technically stack up in the script as they’re technically separated from each other bullet)

You could use the Humanoid.HealthChanged event, but if I were you, I’d just rework the guns to give you the damage value when a player is shot.

1 Like