So, I have this HealthGui, it works fine and on line 5 I have it put this TextLabel's text to the players health. But it gives you the exact digit like for example 90.09248 I would like it to round that number down to 90, or round whatever number it is up or down, but the problem is I don't know how.
Script:
local char = script.Parent.Parent.Parent.Character hum = char.Humanoid hum.Changed:connect(function() script.Parent.Frame.HealthGui.Frame.Size = UDim2.new(hum.Health/hum.MaxHealth,0,1,0) script.Parent.Frame.Text.TextLabel.Text = ""..hum.Health.."/"..hum.MaxHealth.."" if hum.Health <= hum.MaxHealth*0.15 then script.Parent.Frame.HealthGui.Frame.BackgroundColor3 = Color3.new(150/255,0,0) else script.Parent.Frame.HealthGui.Frame.BackgroundColor3 = Color3.new(0,220/255,0) end end)
Lua provides a math.floor
(floor) function and math.ceil
(ceiling) function.
The "floor" of x
is x
without its fractional part. E.g.,
math.floor( 1.1 ) -- 1 math.floor( 1.0 ) -- 1 math.floor( 1.9 ) -- 1 math.floor( 1 ) -- 1 math.floor( -1.5 ) -- -2 math.floor(-2) -- -2
So, this isn't quite rounding (see the 1.9 example). The solution is to just add 0.5 to the value before floor
ing it:
math.floor( x + 0.5 ) --[[ -3 -3 -3 -2.75 -2 -2.5 -2 -2.25 -2 -2 -2 -1.75 -1 -1.5 -1 -1.25 -1 -1 -1 -0.75 0 -0.5 0 -0.25 0 0 0 0.25 1 0.5 1 0.75 1 1 1 1.25 2 1.5 2 1.75 2 2 2 2.25 3 2.5 3 2.75 3 3 ]]