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
1local player = script.Parent.Parent.Parent.Parent.Parent.Parent
2local character = player.Character
3local humanoid = character:FindFirstChild("Humanoid")
4local labelText = script.Parent
5 
6while true do
7labelText = humanoid.Health.."/"..humanoid.MaxHealth
8wait()
9end

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
01local player = game.Players.LocalPlayer --replaced as this is better/easier.
02repeat 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.
03local character = player.Character
04local humanoid = character:WaitForChild("Humanoid") --Changed to WaitForChild as it will wait for Humanoid
05local labelText = script.Parent
06 
07humanoid.Health.Changed:connect(function() --This is better as it will not run a continous loop and cause lag.
08labelText.Text = humanoid.Health.."/"..humanoid.MaxHealth --This was the problem as well, you didn't have the .Text so it wouldn't do anything
09end)
10 
11--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