Answered by
6 years ago Edited 6 years ago
QUESTION: How do I make a player invincible from clicking a button?
MouseClick
has a sole parameter. This parameter passes the Player
object of the player who clicked. This is how we can get the Player.
Example below. Assume YOU are the one who clicks the button.
1 | script.Parent.LightButton.ClickDetector.MouseClick:Connect( function (playerWhoClicked) |
2 | print (playerWhoClicked.Name) |
Now, in order to change a player's health, we need to access the Humanoid
. Fortunately for us, we can do this via the player we just found from clicking the button. To access the Humanoid, we need to locate the Character. You can do this by running this line of code:
1 | script.Parent.LightButton.ClickDetector.MouseClick:Connect( function (playerWhoClicked) |
2 | local Character = playerWhoClicked.Character.Humanoid |
After that, we simply set the MaxHealth
property to X, and Health
to X aswell.
Here's the full code snippet:
1 | script.Parent.LightButton.ClickDetector.MouseClick:Connect( function (playerWhoClicked) |
2 | local humanoid = playerWhoClicked.Character.Humanoid |
3 | humanoid .MaxHealth = 999999999999999999999 |
4 | humanoid .Health = 999999999999999999999 |
Ending note: connect
is deprecated, so you must use Connect
.