How do i constantly check a humanoid's health?

hey there!! so ive been making a damage indicator script and i have a variable named “HumHealth” and its supposed to be the health that you have when you start for example: when you spawn, the HumHealth will be 100 and when u take 10 damage it will be 90, the problem is how do i make it constantly checking? here is the script

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		local UpperTorso = character:WaitForChild("UpperTorso")
		local HumHealth = humanoid.Health --Problem here is that it will only constantly check when a player joins the game
		humanoid.HealthChanged:Connect(function(health)
			healthfunc(health, HumHealth, UpperTorso)
		end)
	end)
end)

Thanks!!

Try this:
It will call the healthfunc when the health changed.

game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild(“Humanoid”)
local UpperTorso = character:WaitForChild(“UpperTorso”)
local HumHealth = humanoid.Health
local oldHealth = HumHealth
while wait() and character do
HumHealth = humanoid.Health
if HumHealth ~= oldHealth then
oldHealth = HumHealth
healthfunc(HumHealth, UpperTorso)
end
end
end)
end)

1 Like

Ill definitely try it thanks!!! :smiley: