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

How to make someone invinable with a click event?

Asked by 6 years ago

using this:can someone help me add a Health: 999999999999999999999

to a script.Parent.LightButton.ClickDetector.MouseClick:connect(function()?

2 answers

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago
script.Parent.LightButton.ClickDetector.MouseClick:Connect(function(player) -- mouseclick event is already emitted with an argument of who clicked the part
    local character = player.Character -- get the player's character
    local humanoid = character:FindFirstChild('Humanoid') -- get the character's humanoid
    if humanoid then
        humanoid.MaxHealth = math.huge -- make character invincible
        humanoid.Health = math.huge
    end
end)
0
where do i put this? in the model or in the part with the script detecctor imaginevreything -50 — 6y
0
In the part with the click detector. MythicalShade 420 — 6y
0
oofit just kills u imaginevreything -50 — 6y
0
Try now with the edited part ( I changed ie8 to math.huge) MythicalShade 420 — 6y
View all comments (3 more)
0
hmm i find it interesting how every mythical shade answer has 2 upvotes... thebayou 441 — 6y
0
? MythicalShade 420 — 6y
0
What's so interesting about that thebayou? MythicalShade 420 — 6y
Ad
Log in to vote
0
Answered by
green271 635 Moderation Voter
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.

script.Parent.LightButton.ClickDetector.MouseClick:Connect(function(playerWhoClicked)
    print(playerWhoClicked.Name) -- output: "imaginevreything"
end)

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:

script.Parent.LightButton.ClickDetector.MouseClick:Connect(function(playerWhoClicked)
    local Character = playerWhoClicked.Character.Humanoid
end)

After that, we simply set the MaxHealth property to X, and Health to X aswell.

Here's the full code snippet:

script.Parent.LightButton.ClickDetector.MouseClick:Connect(function(playerWhoClicked)
    local humanoid = playerWhoClicked.Character.Humanoid
    humanoid .MaxHealth = 999999999999999999999
    humanoid .Health = 999999999999999999999
end)

Ending note: connect is deprecated, so you must use Connect.

0
wait nvm imaginevreything -50 — 6y

Answer this question