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.
1 | local player = game.Players.LocalPlayer |
4 | player.TeamColor = BrickColor.new( "Bright red" ) |
7 | script.Parent.MouseButton 1 Down: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.
1 | local player = game.Players.LocalPlayer |
4 | player.TeamColor = BrickColor.new( "Bright red" ) |
5 | player.Character:WaitForChild( "Humanoid" ).Health = 0 |
8 | script.Parent.MouseButton 1 Down:connect(Click) |
I hope my answer helped you. If it did, be sure to accept it so others know your question has been answered.