Health GUI not rounding up the number

Hey, I recently made this number number GUI that says the number of the players health. But It doesn’t seem to round up the number. (For example the number would say something like: 54.485739558.)
Here’s the health script:

function onHealthChange()
local health = script.Parent.Parent.Parent.Parent.Character.Humanoid.Health
script.Parent.Text = health
if health < 39 then
script.Parent.Parent.Frame.BackgroundColor3 = Color3.fromRGB(255, 125, 127)

elseif health < 40 then
	script.Parent.Parent.Frame.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
end

end

script.Parent.Parent.Parent.Parent.Character.Humanoid.Changed:connect(onHealthChange)

round it with math.round() and then display it

local label = script.Parent
local character = script:FindFirstAncestorWhichIsA("Model")
local humanoid = character:WaitForChild("Humanoid")

function onHealthChange(health)
	label.Text = math.round(health)
	if health <= 40 then
		script.Parent.Parent.Frame.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
	elseif health > 40 then
		script.Parent.Parent.Frame.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
	end
end

humanoid.HealthChanged:connect(onHealthChange)
1 Like

This doesn’t seem to work. Do you know why?

The references might be wrong, you’ve set them fairly awkwardly, I’ll just wrap the health showing bit inside a math.round() call.

function onHealthChange()
	local health = script.Parent.Parent.Parent.Parent.Character.Humanoid.Health
	script.Parent.Text = math.round(health)
	if health < 39 then
		script.Parent.Parent.Frame.BackgroundColor3 = Color3.fromRGB(255, 125, 127)

	elseif health < 40 then
		script.Parent.Parent.Frame.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
	end
end

script.Parent.Parent.Parent.Parent.Character.Humanoid.Changed:connect(onHealthChange)

Alright that works, thanks for the help I’m still trying to get better at scripting.