Hi, I have an issue with my code. I’m trying to make an overhead HP bar but the function is called once or twice when the HP initially changes but not after that.
--//HP handler
local function healthChanged(health, humanoid)
print("called")
local MaxHealth = humanoid.MaxHealth
local CurrentHealth = humanoid.Health
local InfoUI = humanoid.Parent.Head:WaitForChild("Info")
local HealthBar = InfoUI.HealthBack.Health
HealthBar:TweenSize(UDim2.new(CurrentHealth/MaxHealth, 0, HealthBar.Size.Y.Scale, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.1, false)
InfoUI.HealthBack.Display.Text = math.round(CurrentHealth) .. "/" .. MaxHealth
InfoUI.HealthBack.DisplayBACK1.Text = math.round(CurrentHealth) .. "/" .. MaxHealth
end
local function onCharacterAdded(character)
local Humanoid = character:WaitForChild("Humanoid")
--//HP handler
Humanoid.HealthChanged:Connect(function(currentHealth)
healthChanged(currentHealth, Humanoid)
end)
end