i am trying to change the health of a player according to their "power"
how can i change a The LocalPlayers Health?
1 answer
The following code is to be done in a LocalScript. First, let's get the LocalPlayer.
Player = game:GetService("Players").LocalPlayer
To change the Health of the LocalPlayer's Character, we need to get the Character.
Character = Player.CharacterAdded:wait()
This waits until the character is added, and then returns it. Now, we wait for the Humanoid using WaitForChild() and then we can change the Health value of the Humanoid.
Character:WaitForChild("Humanoid").Health = (DesiredValue)
Player = game:GetService("Players").LocalPlayer
Character = Player.CharacterAdded:wait()
Character:WaitForChild("Humanoid").Health = (DesiredValue)
It is important to note that if you want to make the Health greater than 100, you need to change the Humanoid.MaxHealth and then the Health, like
Humanoid.MaxHealth = 500
Humanoid.Health = 500
So, if the Player's "Power" was a value, you could do:
Player = game:GetService("Players").LocalPlayer
Character = Player.CharacterAdded:wait()
Character:WaitForChild("Humanoid").MaxHealth = Power
Character.Humanoid.Health = Power
Once again, this is all to be done in a LocalScript.
Try to watch ROBLOX's scripting tutorials and read over the roblox lua reference. Good luck!
If you need any other help or you're confused with something, leave a comment. If I helped you, let me know by accepting my answer.
12 comments
here is my script, it wont work!
?
local Humanoid = Character:WaitForChild("Humanoid") local LB = Player:WaitForChild("leaderstats") local p = LB:WaitForChild("Power") local Power = 0.1 * p.Value Player = game:GetService("Players").LocalPlayer Player = game:GetService("Players").LocalPlayer Character = Player.CharacterAdded:wait() Character:WaitForChild("Humanoid").Health = (100) Humanoid.MaxHealth = 500 Humanoid.Health = 500 Playe
r.CharacterAdded:wait() Character:WaitForChild("Humanoid").Health = (100) Humanoid.MaxHealth = 500 Humanoid.Health = 500 Player = game:GetService("Players").LocalPlayer Character = Player.CharacterAdded:wait() Character:WaitForChild("Humanoid").MaxHealth = Power Character:WaitForChild("Humanoid").Health = Power
Why do you have so many repeated variables and lines?
because i was lazy and copy pasted my variables that were already there
Player = game:GetService("Players").LocalPlayer Character = Player.CharacterAdded:wait() Humanoid = Character:WaitForChild("Humanoid") LB = Player:WaitForChild("leaderstats") p = LB:WaitForChild("Power") Power = 0.1 * p.Value Humanoid.MaxHealth = Power Humanoid.Health = Power
That's legit all you need. Please accept the answer if it helped you!
when my leaderstats go up, my health doesent change! its a localscript in startercharacter
You need to add a changed event for that. When the Power value changes. Please accept my answer already, this isn't a request website and it's coming to that. I'm doe helping you.
it works!
Great, glad to help.
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
"idk what to write here" A description of what you are trying to do?
https://scriptinghelpers.org/help/how-post-good-questions-answers
well, for one, there are properties of the humanoid called health and maxhealth