✓ 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
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
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
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).
I am using a GUI button (TextButton)
Oh my goodness thanks so much! I have accepted the answer