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

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

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

✓ Accepted answer

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 comments

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)

0

Ah, very clever.

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.

1 comment

0

Its long but it works.

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