So I want a TextLabel to show the players health in Number form.
But I get an error.
But is it even possible?
Here The Script
script.Parent.Text = game.Players.LocalPlayer.Health.Value
So I want a TextLabel to show the players health in Number form.
But I get an error.
But is it even possible?
Here The Script
script.Parent.Text = game.Players.LocalPlayer.Health.Value
âValueâ is not a property of âHealthâ. Health it self is the value and Health is not a property of the Player and instead within the humanoid of the character.:
script.Parent.Text = game.Players.LocalPlayer.Character.Humanoid.Health
Also if you want it to update every time the health changes you can used GetPropertyChangedSignal():
local Player = game.Players.LocalPlayer
local Character = game.Workspace:WaitForChild(Player.Name)
Character.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
script.Parent.Text = Character.Humanoid.Heatlh
end)
Try this
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
Character:WaitForChild("Humanoid"):GetPropertyChangedSignal("Health"):Connect(function()
script.Parent.Text = Character.Humanoid.Health
end)
The name of the variable I had put it wrong. Try again.
Iâm sorry, but if youâre just gonna copy and paste scripts, youâre making yourself more difficult to solve your problem. Please do not rely on copy and pasting, this wouldnât make you a successful scripter. Try solving it on your own.
Make sure the character is loaded in before it requests it.
Assuming this is a LocalScript (it should be anyways)
First, get the player, then use the player instance to get the character (can be from .Character or .CharacterAdded or even better both!)
Second, invoke WaitForChild with the value âHumanoidâ at the character instance you got from declaring it instance
Third, after getting the humanoid, invoke GetPropertyChangedSignal with the value âHealthâ, it will return a RBXScriptSignal. Connect to the RBXScriptSignal and then change the text with the new health value.
Sorry for the bad explanation, but this is the best I can write along with preventing copy-pasting. Copy-pasting will never lead you anywhere.
Could you try it outside of studio?
This should work
local plr = game.Players.LocalPlayer;
local character = plr.Character or plr.CharacterAdded:Wait();
local hum = character:WaitForChild("Humanoid");
game:GetService("RunService").RenderStepped:Connect(function(dt)
script.Parent.Text = hum.Health; -- assuming script.Parent is a text label
end)
This will keep updating the text of the textlabel to humanoidâs health
script.Parent.Text = tostring(game.Players.LocalPlayer.Health.Value)
Incorrect, Health is not a property of LocalPlayer, Health itself is a value of the playerâs Humanoid thus, you cannot write âHealth.Valueâ referring to the humanoidâs health.
You can if Health is an IntValue inside of the player sir.
And what is the need to have a separate intvalue for each playerâs health when Roblox themselves provide you a Health property in a characterâs humanoid?
A lot of people use custom health values for specific things like for example if you wanted to make a player have a death animation when they die, or if you donât want Synapse detecting your health with their built in ESP.
That is not a use case for most of the time, Considering that he has to display the health on textlabel, I DONT find any reason why you need to create a separate IntValue for depicting health, and do all the extra scripting, making events to change the IntValue.
Smart Work > Hard Work
And you would still want to check the Humanoidâs health to change the IntValue in the player unless you want to do the fancy stuff from scratch which is absolutely wasting time.
But hard work benefits you the most.
Anyways regardless to how âpointlessâ it is, you said I was incorrect just because I was using an alternative method to getting the players health when I based it on how the op made this thread primarily.
And yup I know that, but the provided script that the op gave me was just 1 line. Iâm not going to write a whole script down for someone when I can help them solve their problem the âsmarterâ way.
My bad, but you could have specified other details like creating an int value, scripting its events and change the int value in general, at first glance without any context it is incorrect.
If the op actually had a numbervalue/intvalue inside of the player and was wondering why it wasnât displaying a stringvalue, then I think this was the right answer to give. Itâs pretty straightforward really, I think my updated version says enough about how to fix the issue.