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

Make an IntValue health?

Asked by
Mystdar 352 Moderation Voter
10 years ago

I have a localscript inside a TextLabel, in a frame, inside a Frame, in a ScreenGUI inside the player's playerGUI.

This script is supposed to make the TextLabel's text the players health.

local player = game.Players.LocalPlayer --The local player.
    local health = player.Character:WaitForChild("Health") --Yields (makes the script wait) until the apples object becomes available.
    script.Parent.Text= "" .. health.Value
    health.Changed:connect(function() --Connects a function to an event. Known as an anonymous function (as it has no direct identifier.)
        script.Parent.Text = "" .. health.Value --Sets the Text property of the script's parent to "Apples: " then the apples variable's value. The two dots are used for string concatenation (merging of values to form a string.)
    end) --Ends the anonymous function.

Thanks, please post the code in your answer.

2 answers

Log in to vote
2
Answered by 10 years ago

Assuming you're trying to find the Humanoid's health, you should use this:

(Also, you don't need to leave other people's comments in, but if you need a reminder, leave them in)

local player = game.Players.LocalPlayer --The local player.
    local humanoid = player.Character:WaitForChild("Humanoid") --Yields (makes the script wait) until the apples object becomes available.
    script.Parent.Text= "" .. humanoid.Health
    humanoid.Changed:connect(function() --Connects a function to an event. Known as an anonymous function (as it has no direct identifier.)
        script.Parent.Text = "" .. humanoid.Health --Sets the Text property of the script's parent to "Apples: " then the apples variable's value. The two dots are used for string concatenation (merging of values to form a string.)
    end) --Ends the anonymous function.
0
Thanks, however I ran into the problem of the health value becoming 10 decimal digits long, could you round it to an Interger? Mystdar 352 — 10y
0
Just put humanoid.Health inside the parenthesis (brackets) of math.floor() on both lines 3 and 5. Example: math.floor(humanoid.Health) Spongocardo 1991 — 10y
0
Thanks. Mystdar 352 — 10y
Ad
Log in to vote
-1
Answered by
Mr1Vgy 30
10 years ago

Try making changing

local health = player.Character:WaitForChild("Health")

to

local health = player.Character:WaitForChild("Huamnoid")

then do

game.Players.LocalPlayer.Character.Humanoid.Health
1
I have tried to inout your comments in, by failed, as requested, please provide the full code. Mystdar 352 — 10y
1
@Mr1 You spelt Humanoid wrong on the second piece of code. Just giving you a heads up. Spongocardo 1991 — 10y

Answer this question