Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Humanoid health won't print into Gui?

Asked by 8 years ago
local player = script.Parent.Parent.Parent.Parent.Parent.Parent
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
local labelText = script.Parent

while true do
labelText = humanoid.Health.."/"..humanoid.MaxHealth
wait()
end

Thanks :D

1
It should be labelText.Text = humanoid.Health.."/"..humanoid.MaxHealth. The end and beginning "" are not needed as the "/" will make it seem like a string. TinyPanda273 110 — 8y

2 answers

Log in to vote
1
Answered by 8 years ago

""..humanoid.Health.."/"..humanoid.MaxHealth..""

0
That's all I was missing? Thanks a million! LiquifiedState 90 — 8y
0
Incorrect answer. xxxXMrsAwesomeXxxx 70 — 8y
0
I would also disagree on using a loop. Loops are ugly unless they're needed. User#11440 120 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
local player = game.Players.LocalPlayer --replaced as this is better/easier.
repeat wait() until player.Character --Waits for the character to load. You'll need this or else it won't work in game, only for studio. 
local character = player.Character 
local humanoid = character:WaitForChild("Humanoid") --Changed to WaitForChild as it will wait for Humanoid
local labelText = script.Parent

humanoid.Health.Changed:connect(function() --This is better as it will not run a continous loop and cause lag.
labelText.Text = humanoid.Health.."/"..humanoid.MaxHealth --This was the problem as well, you didn't have the .Text so it wouldn't do anything
end)

--This should be a local script btw, I noticed you use the game.Parent.Parent etc, but you could simply do game.Players.LocalPlayer.

Answer this question