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

how can i change a The LocalPlayers Health?

1 answer

✓ Accepted 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

0

here is my script, it wont work!

0

?

0

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

0

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

0

Why do you have so many repeated variables and lines?

0

because i was lazy and copy pasted my variables that were already there

0

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

0

That's legit all you need. Please accept the answer if it helped you!

0

when my leaderstats go up, my health doesent change! its a localscript in startercharacter

0

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.

0

it works!

0

Great, glad to help.

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