i am trying to change the health of a player according to their "power"
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.