How to kill someone if someone clicks a GUI

Hello, I have made a team selector GUI for my Roblox Soccer game but I need to make it kill the player when they click it so they can get the tools

local YourButton = script.Parent
local Team = game.Teams.Away
YourButton.MouseButton1Click:Connect(function()
local PlayersOnTeam = Team:GetPlayers()

if #PlayersOnTeam < 3 then 

	game.ReplicatedStorage.ChangeTeam:FireServer(game.Teams.Away)
else
	
	script.Parent.Text = "Too many Players in Team"
	wait(1)
	script.Parent.Text = "-Home GK"
end

end)

Any help would be much appreciated.

Why killing the player? You can simply clone the tools to their backpack.

1 Like

^ Agree but anyways

Try this:

if #PlayersOnTeam < 3 then
	game.Players.LocalPlayer.Character.Humanoid.Health = 0
	game.ReplicatedStorage.ChangeTeam:FireServer(game.Teams.Away)
else
	script.Parent.Text = "Too many Players in Team"
	wait(1)
	script.Parent.Text = "-Home GK"
end
1 Like

This did not work will try to clone the tools and then tp them to the pitch, thank you.

That is a better method but are you sure your script is a LocalScript? That could be why.

It is a LocalScript so that is probably why your method is not working my bad.

Thank you, made a RemoteEvent then did it and then fired the remoteevent in the script