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

Custom Health GUI showing decimals?

I'm trying to create a custom Health GUI to replace the default Health Coregui. Whenever I take damage, it shows decimal numbers after a digit, for example, 70.002944, but this happens only when the Health increases.

local Humanoid = game.Players.LocalPlayer.Character.Humanoid
local currentHealth = Humanoid.Health
Humanoid.HealthChanged:connect(function(health)
	local change = math.abs(currentHealth - health)
	local healthText = script.Parent.Frame.HealthText
	healthText.Text = "HEALTH:"..currentHealth
	currentHealth = health
end)

2 comments

0

Is this in the GUI and is it a local script?

0

It is in a GUI, and its in a local script.

2 answers

✓ Accepted answer

Just try using math.floor.

local Humanoid = game.Players.LocalPlayer.Character.Humanoid
local currentHealth = Humanoid.Health
Humanoid.HealthChanged:connect(function(health)
    local change = math.abs(currentHealth - health)
    local healthText = script.Parent.Frame.HealthText
    healthText.Text = "HEALTH:"..math.floor(currentHealth)
    currentHealth = health
end)

2 comments

0

It works. Thanks!

0

Mhm, no problem.

local Humanoid = game.Players.LocalPlayer.Character.Humanoid
local currentHealth = Humanoid.Health
Humanoid.HealthChanged:connect(function(health)
    local change = math.abs(currentHealth - health)
    local healthText = script.Parent.Frame.HealthText
    rounded = math.floor(currentHealth) -- I rounded currenthealth using math.floor
    healthText.Text = "HEALTH:".. rounded -- and replaced your variable.
    currentHealth = health
end)

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