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

How to round decimals on a value?

Asked by 1 year ago

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

Log in to vote
1
Answered by
Puppynniko 1059 Moderation Voter
1 year ago

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)
Ad

Answer this question