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

How to round decimals on a value?

I have this health reading gui that reads character health and then converts it into a percent, but the problem is, the value has large amounts of decimal numbers, is there any way I can round off the decimals?

local player = game:GetService("Players").LocalPlayer
local char = player.Character
local Health = char:WaitForChild("Humanoid").Health
local MaxHealth = char:WaitForChild("Humanoid").MaxHealth
local Humanoid = char:WaitForChild("Humanoid")
local percent = (Health/MaxHealth) * 100
local healthtag = script.Parent.Frame.percent

healthtag.Text = percent.."%"


Humanoid.HealthChanged:Connect(function()
	local Health2 = char:WaitForChild("Humanoid").Health
	local MaxHealth2 = char:WaitForChild("Humanoid").MaxHealth
	local percent2 = (Health2/MaxHealth2) * 100
	healthtag.Text = percent2.."%"
end)

here is a picture of it ingame

1 answer

✓ Accepted answer

math.Round()

local player = game:GetService("Players").LocalPlayer
local char = player.Character
local Health = char:WaitForChild("Humanoid").Health
local MaxHealth = char:WaitForChild("Humanoid").MaxHealth
local Humanoid = char:WaitForChild("Humanoid")
local percent = (Health/MaxHealth) * 100
local healthtag = script.Parent.TextLabel

healthtag.Text = percent.."%"

Humanoid.HealthChanged:Connect(function()
	local Health2 = char:WaitForChild("Humanoid").Health
	local MaxHealth2 = char:WaitForChild("Humanoid").MaxHealth
	local percent2 = (Health2/MaxHealth2) * 100
	healthtag.Text = math.round(percent2).."%"
end)

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