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 round off decimals in health text?

Im trying to make it so the text is the same as the health and it works, but i found out that there are decimals and i dont know how to fix that, can some1 help me this is my script so far

local hi = game.Workspace:WaitForChild(game.Players.LocalPlayer.Name) script.Parent.Text = hi.Humanoid.Health game.Workspace:WaitForChild(game.Players.LocalPlayer.Name).Humanoid.HealthChanged:connect(function() script.Parent.Text = hi.Humanoid.Health end)

1 comment

0

You might be better off using string formatting

2 answers

✓ Accepted answer
local hi = game.Workspace:WaitForChild(game.Players.LocalPlayer.Name)
script.Parent.Text = hi.Humanoid.Health
game.Workspace:WaitForChild(game.Players.LocalPlayer.Name).Humanoid.HealthChanged:connect(function()
local roundednum =Instance.new('IntValue') -- a Interger Value will only show up as a number, not decimals
roundednum.Value = hi.Humanoid.Health -- change the value of the Interger Value, and it will round it up
wait(.001)
script.Parent.Text = roundednum.Value -- changes the text
hi.Humanoid.Health = roundednum.Value -- (you can remove this if you want) it will change the player's health without decimals
roundednum:remove() -- clears the rounded number
end)

1 comment

0

Thx so much :D

You can do math.floor or math.ceil. math.floor rounds down, and math.ceil rounds up. Here is a example of what math.floor does.

local heath = 48.7917
print(math.floor(health)) --This will print 48.

This is a example of what math.ceil does.

local health = 63.2539
print(math.ceil(health)) --This will print 64.

Also, when writing scripts on this website, use a code block.

7 comments

0

ok thx ill try it out

0

accept my answer if it works

0

but could u wrewrite my whole script becuz idk where to put it, srry im a beginner

0

what would u like to use? math.ceil or math.floor

0

math.celi

0

and i can pay you abit of robux if you want C:

0

its math.ceil, not math.celi (im late)

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