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

Make an IntValue health?

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

✓ Accepted answer

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.

3 comments

0

Thanks, however I ran into the problem of the health value becoming 10 decimal digits long, could you round it to an Interger?

0

Just put humanoid.Health inside the parenthesis (brackets) of math.floor() on both lines 3 and 5. Example: math.floor(humanoid.Health)

0

Thanks.

Try making changing

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

to

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

then do

game.Players.LocalPlayer.Character.Humanoid.Health

2 comments

1

I have tried to inout your comments in, by failed, as requested, please provide the full code.

1

@Mr1 You spelt Humanoid wrong on the second piece of code. Just giving you a heads up.

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