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

how can i change a The LocalPlayers Health?

Asked by 5 years ago
Edited 5 years ago

i am trying to change the health of a player according to their "power"

0
"idk what to write here" A description of what you are trying to do? User#5423 17 — 5y
0
well, for one, there are properties of the humanoid called health and maxhealth theking48989987 2147 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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.

0
here is my script, it wont work! natonator63 29 — 5y
0
? DaCrazyDev 444 — 5y
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 natonator63 29 — 5y
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 natonator63 29 — 5y
View all comments (8 more)
0
Why do you have so many repeated variables and lines? DaCrazyDev 444 — 5y
0
because i was lazy and copy pasted my variables that were already there natonator63 29 — 5y
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 DaCrazyDev 444 — 5y
0
That's legit all you need. Please accept the answer if it helped you! DaCrazyDev 444 — 5y
0
when my leaderstats go up, my health doesent change! its a localscript in startercharacter natonator63 29 — 5y
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. DaCrazyDev 444 — 5y
0
it works! natonator63 29 — 5y
0
Great, glad to help. DaCrazyDev 444 — 5y
Ad

Answer this question