Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

2 comments

0

And to round to the nearest number, math.floor(x+.5)

0

Thanks.

This discussion is preserved as it was. New answers, comments, and votes are closed.