Health bar Innacuracy

local function updatehealth()
	local health = humanoid.Health / humanoid.MaxHealth --Maths

	--local info = TweenInfo.new(humanoid.Health / humanoid.MaxHealth,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0) --Tween Info

	--TW:Create(gui.Health.HealthBar,info,{Size = UDim2.fromScale(health, gui.Health.HealthBar.Size.Y.Scale)}):Play() -- Create The Tween Then Play It
	
	gui.Health.HealthBar:TweenSize((UDim2.new(health,0,gui.Health.HealthBar.Size.Y.Scale,0)),Enum.EasingDirection.InOut,Enum.EasingStyle.Quad,0.5)
	gui.ActualText.HP.Text = math.floor(humanoid.Health)

end

For some ungodly reason i cant seem to get my health bar to accurately work:


When not clamping my health values, it stays out of the confined space i want it i
when i clamp its values to stay in said box, it does not track properly

local health = math.clamp(humanoid.Health / humanoid.MaxHealth, 0, 0.737)

image
For reference it should look like this:
image
When i clamp the values, it accurately shows my health at 100% but once i set my huamnoids hp to 50 the bar stays at around 75% rather than accurately showing it at 50%

2 Likes

whats the size of the healthbar container

1 Like

image

{0.32, 0},{0.067, 0} is "health"
{0.744, 0},{0.574, 0} for is healthbar

heres what the health bar parent outline looks like so its probably not really centered

1 Like

Try multiplying health in (UDim2.new(health,0... by the maximum value. Health current is a value between 0 and 1, however you need it to be a value between 0 and 0.744, which multiplying achieves

(UDim2.new(health * 0.744, 0, gui.Health.HealthBar.Size.Y.Scale, 0)
2 Likes

ty ty my friend with a little bit of tweaking this worked perfect

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.