Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My Health Wont Display On My Text Label whats wrong with it?

I Honestly Can't Figure out what's wrong with it i just recently got back to scripting and I was never too good at it lol

local player = game:GetService("Players")
local text = script.Parent 

player.Character.Humanoid:GetPropertyChangedSignal("Health"):Connect(function() 
	text.Text = player.Character.Humanoid.Health
end)

1 comment

0

I want My health to display on my Textlabel and update when it goes down and up

1 answer

First off it should be a local script because GUIs are locally designated. secondly Players only contain well, players, no characters. Instead do this (script is now edited):

local player = game.Players.LocalPlayer
local character = player.Character
local hum = character.Humanoid
local text = script.Parent

character.Humanoid.HealthChanged:Connect(function()
	text.Text = (math.floor(hum.Health).." / "..hum.MaxHealth.." HP")
end)

player.CharacterAdded:Connect(function(newChr)
	chr = newChr
	hum = newChr:WaitForChild("Humanoid")
	text.Text = (math.floor(hum.Health).." / "..hum.MaxHealth.." HP")
	hum.HealthChanged:Connect(function()
		text.Text = (math.floor(hum.Health).." / "..hum.MaxHealth.." HP")
	end)
end)

5 comments

0

@NGC4637 I Tried local player = game.Players.LocalPlayer local character = player.Character local text = script.Parent character.Humanoid.HealthChanged:Connect(function() text.Text = character.Humanoid.Health end) But It Still doesn't work

0

Maybe just try text.Text = character.Humanoid.Health

0

dud just make a stringValue , if the script is in the TextLabel and its name is text just first get the stringValue by getting the replicated storage , or u can just do StringValue = game.ReplicatedStorage.StringValue, then just do text.Text = StringValue.Value

0

Filthy did you get any errors in the developer console?

0

either way i've remade the script

This discussion is preserved as it was. New answers, comments, and votes are closed.