Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make this Health Bar not show stuff like .264808654785?

Asked by 8 years ago

Can someone tell me how I would make this Health Bar script remove the 264808654785 in 49.264808654785 so it just show's the 49?

Code:

local player = game:GetService("Players").LocalPlayer -- Probably doesn't need GetService, oh well.
local char = player.Character
local text = script.Parent:FindFirstChild("Text")
local frame = script.Parent:FindFirstChild("ColorFrame")

char.Humanoid.HealthChanged:connect(function()
    frame:TweenSize(UDim2.new(0,2*char.Humanoid.Health,1,0),"Out","Quad",0.000001)
    text.Text = "Health: "..char.Humanoid.Health.." / "..char.Humanoid.MaxHealth
end)

1 answer

Log in to vote
3
Answered by
NotSoNorm 777 Moderation Voter
8 years ago

Simple!

We use math.floor / math.ceil

So say you want to round up, We'd use math.ceil. (ceil is short for ceiling which mean roof), Vice versa for math.floor.

local player = game:GetService("Players").LocalPlayer -- Probably doesn't need GetService, oh well.
local char = player.Character
local text = script.Parent:FindFirstChild("Text")
local frame = script.Parent:FindFirstChild("ColorFrame")

char.Humanoid.HealthChanged:connect(function()
    frame:TweenSize(UDim2.new(0,2*char.Humanoid.Health,1,0),"Out","Quad",0.000001)
    text.Text = "Health: "..math.floor(char.Humanoid.Health).." / "..char.Humanoid.MaxHealth
end)

0
And to round to the nearest number, math.floor(x+.5) DigitalVeer 1473 — 8y
0
Thanks. ISellCows 2 — 8y
Ad

Answer this question