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

Is there a way to make the humanoid's health not appear in decimals?

Asked by 9 years ago

I'm making my own health gui, and whenever the player takes damage, it comes up as something like

47.00212831842 etc.

is there a way so it just appears as its 47?

my script:

plr = game.Players.LocalPlayer

while true do
    wait()
    script.Parent.Text = plr.Character.Humanoid.Health
end

I know the script isn't that efficient but it does the job.

2 answers

Log in to vote
4
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

You can use math.floor to round a number down to the nearest integer.

print(math.floor(47.3)) --47
--Rounds it towards the floor

You can also use math.ceil to round a number up to the nearest integer.

print(math.ceil(47.8)) --48
--Rounds it towards the ceiling

The problem with these methods is that they don't work like true rounding, going up with any decimals 5 or greater. To get true rounding, you would have to do some additional checks or string patterns.

2
If you want to do true rounding, you can just get the floor value of the the number plus 0.5. That way, if the decimal portion of the number is 0.5 or greater, it will round up, but if it's not, it will round down. Like this: math.floor(Num + 0.5) TurboFusion 1821 — 9y
0
Ah, very clever. Perci1 4988 — 9y
Ad
Log in to vote
0
Answered by
Hero_ic 502 Moderation Voter
9 years ago

Why not do this?

local plr = game.Players.LocalPlayer
--Create a health variable
local hth = plr.Character.Humanoid.Health

while true do
    wait()
    if hth > 49 --If health is greater then 49 because of decimals
    script.Parent.Text = 49 -- make the text = 49 and keep doing this so on
    else if hth>50
    script.Parent.Text = 50
    end
    --And go so on this is my best explanation I hope its good
end

I don't know if the script is efficient but that is the way I found doing it. It probably takes a very long process to do it like this though.

The best idea I have is to make the health 12 or something then make everything else take very little health like 0.05.

0
Its long but it works. Operation_Meme 890 — 9y

Answer this question