Why isn't this BillboardGui changing with the Humanoid's health?

I can’t see any problems with this script but the text just isn’t syncing with the humanoid’s health. I have checked the ouput which has no errrors whatsoever.

I tried changing

humanoid.Health.Value

to

humanoid.Health

but that didn’t work either.

    --//By shish_kebab3

--//Variables\\--

local beast = script.Parent
local head = beast:WaitForChild("Head")
local humanoid = beast:WaitForChild("Humanoid")

local gui = head:WaitForChild("BillboardGui")
local frame = gui:WaitForChild("Frame")
local healthLabel frame:WaitForChild("Health")

--//Functions\\--

local function update()
	healthLabel.Text = humanoid.Health.Value.."/"..humanoid.MaxHealth.Value
	
	if humanoid.Health <= 7500 then
		healthLabel.TextColor3 = Color3.fromRGB(255, 170, 0)
		healthLabel.TextStrokeColor3 = Color3.fromRGB(99, 66, 0)
		
		elseif humanoid.Health <= 5000 then
		healthLabel.TextColor3 = Color3.fromRGB(170, 85, 0)
		healthLabel.TextStrokeColor3 = Color3.fromRGB(125, 62, 0)
		
	       elseif humanoid.Health <= 2500 then
		   healthLabel.TextColor3 = Color3.fromRGB(255, 0, 0)
		   healthLabel.TextStrokeColor3 = Color3.fromRGB(125, 0, 0)
		
		
	end
		end
				
		
humanoid.HealthChanged:connect(function()
	update()
end)

You’re trying to access a property of a property, which isn’t possible. Change this to just humanoid.Health and change humanoid.MaxHealth.Value to humanoid.MaxHealth

I tried that and it had no effect

Is this a LocalScript?

No this is serverscript

Try this:

local beast = script.Parent
local head = beast:WaitForChild("Head")
local humanoid = beast:WaitForChild("Humanoid")

local gui = head:WaitForChild("BillboardGui")
local frame = gui:WaitForChild("Frame")
local healthLabel = frame:WaitForChild("Health")

local function update()
	healthLabel.Text = humanoid.Health.Value.."/"..humanoid.MaxHealth.Value
	
	if humanoid.Health <= 7500 then
		healthLabel.TextColor3 = Color3.fromRGB(255, 170, 0)
		healthLabel.TextStrokeColor3 = Color3.fromRGB(99, 66, 0)
		
	elseif humanoid.Health <= 5000 then
		healthLabel.TextColor3 = Color3.fromRGB(170, 85, 0)
		healthLabel.TextStrokeColor3 = Color3.fromRGB(125, 62, 0)
		
	elseif humanoid.Health <= 2500 then
	   healthLabel.TextColor3 = Color3.fromRGB(255, 0, 0)
	   healthLabel.TextStrokeColor3 = Color3.fromRGB(125, 0, 0)
	end
end
				
		
humanoid:GetPropertyChangedSignal("Health"):Connect(function()
	update()
end)
3 Likes

Yep, I just realised it said

local healthLabel frame:WaitForChild(“Health”)

:+1:

1 Like

Side note, you don’t need to create a new function here:

You can just do:

humanoid.HealthChanged:Connect(update)
2 Likes

Thanks, I didn’t know I could do that.

The Connect method takes a function as a parameter. You can pass an anonymous function (:Connect(function() end)) or passing a function that already exists (without calling it!! :Connect(myFunctionHere)).