I have some health bar gui script here.
humanoid:GetPropertyChangedSignal("Health"):Connect(function(health)
local base = script.Parent.Tray:WaitForChild("HealthBar")
local healthPercent = humanoid.Health / humanoid.MaxHealth
if humanoid.Health <= humanoid.MaxHealth then
tweens:Create(base.Fill, TweenInfo.new(math.abs(LastHealth-humanoid.Health)/humanoid.MaxHealth, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {Size = UDim2.new(healthPercent, 0, 1, 0), ImageColor3 = getHealthBarColor(healthPercent)}):Play()
else
tweens:Create(base.Fill, TweenInfo.new(0.25, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {Size = UDim2.new(1, 0, 1, 0), ImageColor3 = HealthOverhealColor}):Play()
end
LastHealth = humanoid.Health
base.Fill.HealthNumber.Text = LastHealth..'/100'
end)
The thing is that where it displays the health number, it can sometimes put decimal numbers. Which I donβt want.

How do I get rid of the decimal numbers?
1 Like
Use math.round(Your number) to do it.
For your case you do
humanoid:GetPropertyChangedSignal("Health"):Connect(function(health)
local base = script.Parent.Tray:WaitForChild("HealthBar")
local healthPercent = humanoid.Health / humanoid.MaxHealth
if humanoid.Health <= humanoid.MaxHealth then
tweens:Create(base.Fill, TweenInfo.new(math.abs(LastHealth-humanoid.Health)/humanoid.MaxHealth, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {Size = UDim2.new(healthPercent, 0, 1, 0), ImageColor3 = getHealthBarColor(healthPercent)}):Play()
else
tweens:Create(base.Fill, TweenInfo.new(0.25, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {Size = UDim2.new(1, 0, 1, 0), ImageColor3 = HealthOverhealColor}):Play()
end
LastHealth = humanoid.Health
base.Fill.HealthNumber.Text = math.round(LastHealth)..'/100'
end)
2 Likes
you can use math.Floor()
to round the health down, removing the decimal places.
Inversely, you can use math.Ceil()
to round the number up.
Both methods remove the decimal places.
Thanks for this lol. I forgot that math.round()
existed!
1 Like
system
(system)
Closed
#5
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.