How to print reduced health?

Hi devs,

I’m trying to make it so it prints the health that has been reduced, is there a way I can do that ?

2 Likes

Depends on what exactly you are trying to do, please give more details.

Normally, you choose the Health that is being removed, so why don’t you print that number?

Example:

local HealthToRemove = 25

Humanoid:TakeDamage(HealthToRemove)
print(HealthToRemove)
2 Likes

For example, you have 100 Health and you take 10 Damage. The thing i’m trying to do is print the amount of damage I’ve taken.

Let me show you my code.

image

image

image

The problem I currently have is that I took 10 Damage but it prints “0”

1 Like

Yes, it prints 0 since you are doing CurrentHealth - CurrentHealth, it’s like 10 - 10. Thats why it is 0.

Instead of making super complicated scripts that will detect that number, why don’t you print the Health that you are removing in the script that is doing it.

Look at the example I gave above.

3 Likes

Try changing Humanoid.Health to Humanoid.MaxHealth and then try the script again.

3 Likes

Nope, it wont work correctly:
Let’s say you have 50 Health, but the MaxHealth is 100, you remove 10, instead of printing 10 it will print 60.

2 Likes

This script should work since it uses the old health value and minuses that by the new health value.

Player.CharacterAdded:Connect(function(Character)
	task.wait(2)
	local LastHealth = Character.Humanoid.Health
	Character.Humanoid.HealthChanged:Connect(function(Value)
		local Reduced = LastHealth-Value
		LastHealth = Value
	end)
end)
2 Likes
local Humanoid = Dummy:FindFirstChild("Humanoid")
Humanoid.Health.HealthChanged:Connect(function(HealthChanged)
      print("Dummy has been damaged, the new remaning health is " ... HealthChanged)

end
3 Likes

Yeah but that doesn’t print how much damage you’ve taken, that prints your current health.

2 Likes

I believe this could work! :grinning:

Humanoid.Health.HealthChanged:Connect(function(Health)
    print(Humanoid.MaxHealth - Health)
end)

I hope that helped you ! :yum:

2 Likes

No sorry that would not work. It will print 100 (your maxhealth) - your health.

Also you made a mistake. It shouldn’t be Humanoid.Health.HealthChanged but Humanoid.HealthChanged

Thanks for trying tho

2 Likes

I will look for another solution !
:wink:

2 Likes

so I guess what you can do is

local health = 100
hum.HealthChanged:Connect(function()
print(health-hum.Health)
health = hum.Health
end)
2 Likes

I think you can place a print(damage) where you put damage scripts! :wink:

1 Like

also this can work in any script

Can you show me the script to see what I could do ?

What’s the ‘Health’ variable for?

1 Like

it is the health before the deduction aka 100 or u can set it to hum.MaxHealth

1 Like

No, because you remove the player’s current life from that of the max life, so it only works the first time!

1 Like

wrong it doesnt it works multiple times

1 Like