Damage indicator not working properly?

Ive made a lot of posts about this but its still not fixed, ive fixed 4 bugs and there is 1 last bug… i am making a damage indicator where everytime a player gets damaged a gui shows up showing how much damage the player took.

So, ive made it and uh made the damage indicator it works but for example: player has 100 hp and now their hp is 90, it says 10… but what if the player took damage again, they took 10 damage and their hp is now 80, but the gui says 20…

Ive tried searching for hours in the forum and coudnt find any, if i missed one topic saying about this then let me know!

		local NewCurrentHealth = health - CurrentHealth --for ex: 90(health) - 100 (currenthealth) = -10
		local damageTaken2 = math.abs(NewCurrentHealth) --10
		local NewCurrentHealth = damageTaken2 - CurrentHealth --10 - 100 = -90
		local newCurrentHP = math.abs(NewCurrentHealth) --90
		local damageTaken = CurrentHealth - newCurrentHP --100 - 90 = 10

--thing is, when u change 90 to 80 it will be -20 which if u do 1 punch (10) then another (10) it will say second did 20 but in reality it did 10 :/

If you have any idea on how to fix this then tell me, thanks!!

I think you’re forgetting to set CurrentHealth to the current health after the damage is dealt. after you did the damage, currenthealth remains at 100, which means subsequent calculations will think the player went from 100 to whatever health they have now. just add CurrentHealth = health after you calculate the damage amount.

2 Likes

Yeah, just came up with the solution but mine is more messy and requires more lines so ill be using ur idea since it doesnt require too many lines to do so (prob only 1) while mine requires atleast 3 lines lol
So yeah, just wanna thank you for the idea!!