Trying to figure out whether change in health was a decrease or increase

Hi I just have a tiny little problem. The problem is if the change in player’s health was a increase or decrease. So far from the roblox website, I was able to figure out by how much the player’s health has changed. I just don’t know how to figure out if that change in health was a decrease or increase.

Here’s my script:

local Currenthealth = Humanoid.Health
Humanoid.HealthChanged:Connect(function(Health)
	wait(0.01)
	local abs = math.abs(CurrentHealth - Health)
	HealthBarSize.Size = UDim2.new(Humanoid.Health/Humanoid.MaxHealth,0,1,0)
	HealthNumber.Text = math.floor(Humanoid.Health).."/"..math.floor(Humanoid.MaxHealth)
	TextLabel.Size = UDim2.new(HealthBarSize.Size.X.Scale - testing.Size.X.Scale,0,1,0)
	TextLabel.Position = UDim2.new(HealthBarSize.Size.X.Scale/2 + HealthBarSize.Size.X.Scale/2 + TextLabel.Size.X.Scale/-2 + TextLabel.Size.X.Scale/-2,0,0,0)
	CurrentHealth = Health
	wait(0.05)
end)

Any articles or examples would be greatly helpful! :smiley:

2 Likes

You could do something like:


local Currenthealth = Humanoid.Health

Humanoid.HealthChanged:Connect(function(Health)
	if Health > Currenthealth then
		print("Health Increased")
	else
		print("Health Decreased")

	end
end)
1 Like

Alright, let me try that. Will let you know if it works.

Yep it didn’t work. Once the health regens it still says the health was decreased. It’s supposed to say it increased

The script I gave is just an example. You will have to update the Current health each time (or it will do the error you said). Try something like

Humanoid.HealthChanged:Connect(function(Health)
	if Health > Currenthealth then
		print("Health Increased")
		
	else
		print("Health Decreased")

	end
	Currenthealth= Health
end)
2 Likes

Yes, I did do that, Same output

You could possibly do this:

local Currenthealth = Humanoid.Health

local StoreHealth = 0
StoreHealth = Currenthealth

Humanoid.HealthChanged:Connect(function(Health)
	if Health > StoreHealth then
		print("Health Increased")
	else
		print("Health Decreased")

	end

       StoreHealth = CurrentHealth
end)

idk if this will work

Alright, trying this right now :slightly_smiling_face:

Alright. This didn’t work but then I tryed @Infinite_Visions and it did work. But thank for using your time to help me! :smiley:

how did it work?
im still trying to figure out how to use it…but all i get is a huge mess!

1 Like