Is there a way to fix the lots of numbers when checking the humanoid's health?

Hello, i have been trying to fix this problem in the health bar system for a while and i still don’t know how to fix it. :frowning:
https://i.gyazo.com/87693df7c8328151108c8b64c0501942.gif

Paste your script here and I can fix it.

This is the health bar code

local function UpdateHealthBar()
	local Health = Character:WaitForChild('Humanoid').Health
	local MaxHealth = Character:WaitForChild('Humanoid').MaxHealth
	HealthBar.BackgroundColor3 = HealthColor.Value
	HealthBG:WaitForChild('TextLabel').Text = (Health / MaxHealth * 100)..'%'
	local health = UDim2.new((Health / MaxHealth), 0, 1, 0)
	local info = TweenInfo.new(0.1, Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0)
	local t = TweenService:Create(HealthBar, info, {Size = health})
	t:Play()
end

You can use math.round to round down your health percentage to the nearest whole number.

Fixed code:

local info = TweenInfo.new(0.1, Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0)

local function UpdateHealthBar()
	local Humanoid = Character:WaitForChild("Humanoid")
	local Health = Humanoid.Health
	local MaxHealth = Humanoid.MaxHealth
	
	HealthBar.BackgroundColor3 = HealthColor.Value
	HealthBG.TextLabel.Text = math.round(Health / MaxHealth * 100) .."%"
		
	local healthTween = TweenService:Create(HealthBar, info, {
		Size = UDim2.new(Health / MaxHealth, 0, 1, 0)
	})
	
	healthTween:Play()
end

Thanks! it worked very well :smiley:
aaaa

1 Like

No problem. If you have any more questions, feel free to ask.

(also if you want to bypass the character limit, just paste image as many times as it takes to go over the character limit)

I’ve encountered this problem a few weeks ago too, yeah you gotta use math.round as @Katrist said, and I didn’t know that you could use

To bypass the character limit

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