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

How can I make 0 humanoid health on click?

Okay so I am trying to make it so if you press the button to change teams you reset and then you change teams. Here is the script:

function Click(mouse)
script.Parent.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("Bright red")
end


script.Parent.MouseButton1Down:connect(Click)

I want to know how to make it reset your character when you click the button as well as change teams. Please help, thanks for reading this and double thanks if you make a comment or answer for this.

3 comments

0

Are you using a ClickDetector in a part or a GUI button (E.G: TextButton or ImageButton) with your script? Also, use a code block to place your script's code in (it's the Lua symbol when you post a question/answer).

0

I am using a GUI button (TextButton)

0

Oh my goodness thanks so much! I have accepted the answer

1 answer

✓ Accepted answer

Assuming you are using a GUI button (TextButton or an ImageButton), you could just use a LocalScript to get the player and make life easier for yourself.

local player = game.Players.LocalPlayer --Get the LocalPlayer.

function Click() 
	player.TeamColor = BrickColor.new("Bright red")
end

script.Parent.MouseButton1Down:connect(Click)

Getting the player's character:

To make it so you can kill the player, you need access to the character. Fortunately, there's a property called Character in every player that directs you to the player's character, so you can gain access to the humanoid and set it's health to 0.

To avoid errors, you could also use the WaitForChild method to wait until the Humanoid becomes available.

local player = game.Players.LocalPlayer --Get the LocalPlayer.

function Click() 
	player.TeamColor = BrickColor.new("Bright red")
	player.Character:WaitForChild("Humanoid").Health = 0
end

script.Parent.MouseButton1Down:connect(Click)

I hope my answer helped you. If it did, be sure to accept it so others know your question has been answered.

3 comments

1

There's no need for the 'mouse' parameter on line 3.. as the MouseButton1Down event doesn't even return the mouse..

0

Yeah, I forgot to remove that. :)

0

It's okay it works anyway, a huge thank you Spongocardo, now when my GUI is on I click a job and it resets my character and I join that team! :)

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