How would I make a textbox show how much health a player has?

I’m a new developer who has almost no experience in scripting and I am trying to make a script that changes the text in a label to the amount of health a player has. How would I do that?

You could add a local script inside the text label, and use Changed event for health, so when it changes, the textLabel.text is set equal to the humanoid’s actual health

In a local script inside of a TextLabel:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
script.Parent.Text = "100"

character.Humanoid.HealthChanged:Connect(function(health)
script.Parent.Text = health
end)
5 Likes

I think you mean TextLabel??

So first you would need to get the Character’s Humanoid reference then put that text onto the Label. Since we are doing guis, local scripts would be the way to go.

local plr = game:GetService("Players").LocalPlayer
local TextDisplay = script.Parent --Your label directory

plr.Character.Humanoid:GetPropertyChangedSignal("Health"):Connect(function() --Checking every time health changes
    TextDisplay.Text = tostring(plr.Character.Humanoid.Health) --Updating the text
end)
2 Likes