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

How can I make 0 humanoid health on click?

Asked by 9 years ago

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.

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). Spongocardo 1991 — 9y
0
I am using a GUI button (TextButton) STICKYBUN10 19 — 9y
0
Oh my goodness thanks so much! I have accepted the answer STICKYBUN10 19 — 9y

1 answer

Log in to vote
2
Answered by 9 years ago

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.

1
There's no need for the 'mouse' parameter on line 3.. as the MouseButton1Down event doesn't even return the mouse.. Goulstem 8144 — 9y
0
Yeah, I forgot to remove that. :) Spongocardo 1991 — 9y
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! :) STICKYBUN10 19 — 9y
Ad

Answer this question