Rounding Numbers on UI + Health won't go up to max health

So I made a health gui that displays your current health (obviously) but when the health is being shown in numbers, it goes all the way to the decimals and I want it to round to the nearest 1 digit.

Screen Shot 2022-06-14 at 18.31.46

I also want to talk about how the max health on a player is set to 255 but after the humanoid gets damaged, it only heals up to 100.

How can I fix either of these?

1 Like

To fix the rounding issue, you can use math.floor().
To fix the healing issue, you could probably try setting Humanoid.MaxHealth and Humanoid.Health to 255.

use math.floor

math.floor(Humanoid.Health + 1)
1 Like

I already set Humanoid.MaxHealth and Humanoid.Health to 255 but it didn’t work.

It might be a Roblox issue then, since I can’t find any other values in Humanoid that would relate to healing.

1 Like
local TextHP = script.Parent
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
while wait() do
TextHP.Text ="Health:"..math.floor(Char:WaitForChild("Humanoid").Health).."/"..math.floor(Char:WaitForChild("Humanoid").MaxHealth)
end

If you’re changing the health on client side then the hp will be back to 100 try change it on server side

1 Like

I recommend using math.round() over math.floor() so it can round up and down to the nearest whole number

3 Likes

I also want to talk about how the max health on a player is set to 255 but after the humanoid gets damaged, it only heals up to 100.

This sounds like a client-server replication issue, i.e; you’re setting the player’s humanoid’s ‘MaxHealth’ property to 255 on the client, this change will not reflect to the server meaning that from the server’s perspective the humanoid’s ‘MaxHealth’ property is still 100 and thus the ‘Health’ script which automatically heals player’s humanoids only heals the humanoid back to 100 health.

better way to fix this is to math.floor() in the health script in the character so you only heal with whole numbers