Here is the code, so you can figure out what is wrong here.
local bar = script.Parent.Bar
local healthBar = script.Parent.Health
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local colorRed = Color3.fromRGB(255, 0, 25)
local colorDefault = Color3.fromRGB(146, 237, 255)
while wait() do
if not char:FindFirstChild("Humanoid") then return end
local health = char.Humanoid.Health
local maxHealth = char.Humanoid.MaxHealth
if char.Humanoid.Health <= 25 then
healthBar.BackgroundColor3 = colorRed
end
if char.Humanoid.Health > 25 then
healthBar.BackgroundColor3 = colorDefault
end
healthBar.Size = UDim2.new(bar.Size.X.Scale / maxHealth * health, 0, healthBar.Size.Y.Scale, 0)
end
Only use one of the bars to get the new size. I think the issue here is that one bar is a little smaller and that messes up the calculation since you mix them in the size assigment.
Basically, in this assigment - healthBar.Size = UDim2.new(bar.Size.X.Scale / maxHealth * health, ...), you are trying to set the size of one of the bars, but you use a different bar’s size to calculate the size. So instead do - bar.Size = UDim2.new(bar.Size.X.Scale / maxHealth * health, ...).
But I HIGHLY recommend just putting the transparent outline bar inside the opaque bar and setting the size to like 1.1, 0, 1.1, 0 so it’s a little bigger. It will then resize automatically and you dont have reference two separate bars.
Also, you should absolutely not use a while loop for detecting a health change. Use humanoid.HealthChanged:Connect(function(health) ... end) instead.