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

Health number gui?

Asked by
Kryddan 261 Moderation Voter
9 years ago

Hey i try to make a Gui that says youre current health example : Current Health: 50

Here is my code that is in the Textlabel

game.Players.PlayerAdded:connect(function(player)
    local np = player.Humanoid.Health
    script.Parent.Text = np
end)

1 answer

Log in to vote
1
Answered by 9 years ago

Okay so, you cannot have a PlayerAdded inside a localscript, and you cannot call the health value in a variable. Use a localscript, and put the following lines:

local player = game.Players.LocalPlayer
repeat wait() until player.Character  -- we wait until player has loaded
local character = player.Character
local hum = character:WaitForChild('Humanoid') -- cant call the 'Health', it has to be called in the script, and wait for humanoid to load
script.Parent.Text = 'Current Health: ' .. hum.Health -- we print the humanoid's health, and use double dots to connect the variable with text
0
Thx dude youre a legend Kryddan 261 — 9y
Ad

Answer this question