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

How to make someone invinable with a click event?

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

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

2 answers

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

7 comments

0

where do i put this? in the model or in the part with the script detecctor

0

In the part with the click detector.

0

oofit just kills u

0

Try now with the edited part ( I changed ie8 to math.huge)

0

hmm i find it interesting how every mythical shade answer has 2 upvotes...

0

?

0

What's so interesting about that thebayou?

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.

1 comment

0

wait nvm

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