Help with displaying health

So I am trying to display the players health this is what I tried but there are no errors or anything in the output

Local Script:

local players = game:GetService("Players")
local player = players.LocalPlayer
local char = player.Character
local hum = char:WaitForChild("Humanoid")
local text = script.Parent.Text

while true do
	text = hum.Health .. "" 
	wait(0.00001)
	text = hum.Health .. "" 
end

Don’t save the instance’s property, as it saves the value instead of the location/index, so when you are trying to change the text it only changes the variable and not the TextLabel’s property

local players = game:GetService("Players")
local player = players.LocalPlayer
local char = player.Character
local hum = char:WaitForChild("Humanoid")
local label = script.Parent --save the instance instead, the game assumes you are saving the text and not the property location

hum:GetPropertyChangedSignal("Health"):Connect(function() --this event fires whenever the "Health" property changes
	label.Text = hum.Health .. "" 
end)

Yeah, so this is pretty much all you have to do
(Updated Version of @mniao )

local player = game.Players.LocalPlayer
local hum = player.Character:WaitForChild("Humanoid")
local text = script.Parent.Text

text = hum.Health -- Extra Security to set text to health
hum:GetPropertyChangedSignal("Health"):Connect(function()
	text = hum.Health 
end

Appearently using a loop is a bad thing

That version will not work, you are updating the text variable instead of the textlabel’s property

Not sure if you are reading but Its Getting the Property of the TextLabel, it works

Just tested it, your code does not work.

Works for me

Edit: i see the error :

Are you simply printing or actually changing the textlabel’s text? as printing will work but actually changing the property will not.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.