Health bar issue

i’ve been working on an arcade-style game; and i need to add a health bar…
i tried so many ways… i’m not very good at math not this complex math at least;
a few examples:

character2.Humanoid.HealthChanged:Connect(function()
	ui2.healthbar2.Size = UDim2.new(0,(character2:WaitForChild("Humanoid").Health/character2:WaitForChild("Humanoid").MaxHealth*375),.057, 0)
	ui.healthbar2.Size = UDim2.new(0,(character1:WaitForChild("Humanoid").Health/character1:WaitForChild("Humanoid").MaxHealth*375),.057, 0)
end)
character1.Humanoid.HealthChanged:Connect(function()
	ui2.healthbar1:TweenSize(UDim2.new(character1.Humanoid.Health/100,0,0,100),"Out","Quint",0.25)
	ui.healthbar1:TweenSize(UDim2.new(character1.Humanoid.Health/100,0,0,100),"Out","Quint",0.25)
end)

both of these just make my health bar disappear.

here is the size of the health bars (there is two)
{13.66, 0},{5.41, 0}
{13.265, 0},{5.41, 0}

could someone help me make the health bars work?

1 Like

Is this locally/serversided and who is character1 and character2?

this is serversided. character1 and character2 are arguements passed that show who are inside the round (this is 1 person vs 1 person)

Performing actions in UIObjects should always be client-sided. You can fire a RemoteEvent to pass the characters to the client.

okay… but even so, if i did that i will still have the same issue, the tweening size / setting size is not working correctly.

This should help.

local TweenService = game:GetService("TweenService")
local UI = path.to.UI --where your UI is

local function SetEvent(char)
    local Hum = char:FindFirstChild("Humanoid")
    if Hum then
        Hum.HealthChanged:Connect(function()
            local Track = TweenService:Create(UI.healthbar2, TweenInfo.new(0.25, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {Size = UDim2.fromScale(Hum.Health / Hum.MaxHealth, 1)})
            Track:Play()
        end)
    end
end

it just makes the health bar disappear, as it was before…