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

How do i round off decimals in health text?

Asked by 6 years ago

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)

0
You might be better off using string formatting User#5423 17 — 6y

2 answers

Log in to vote
0
Answered by
Rawblocky 217 Moderation Voter
6 years ago
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)
0
Thx so much :D lukebloxdaily 6 — 6y
Ad
Log in to vote
12
Answered by 6 years ago
Edited 5 years ago

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.

0
ok thx ill try it out lukebloxdaily 6 — 6y
0
accept my answer if it works hiimgoodpack 2009 — 6y
0
but could u wrewrite my whole script becuz idk where to put it, srry im a beginner lukebloxdaily 6 — 6y
0
what would u like to use? math.ceil or math.floor hiimgoodpack 2009 — 6y
View all comments (3 more)
0
math.celi lukebloxdaily 6 — 6y
0
and i can pay you abit of robux if you want C: lukebloxdaily 6 — 6y
0
its math.ceil, not math.celi (im late) luadotorg 194 — 6y

Answer this question