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.
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.
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.