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

Custom Health GUI showing decimals?

Asked by 8 years ago

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)
0
Is this in the GUI and is it a local script? iSvenDerp 233 — 8y
0
It is in a GUI, and its in a local script. Raven_Caedes 95 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

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)

0
It works. Thanks! Raven_Caedes 95 — 8y
0
Mhm, no problem. TypicalModerator 110 — 8y
Ad
Log in to vote
1
Answered by 8 years ago
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)

Answer this question