I have a script in ServerScriptService which is as follows

local TeamChangeEvent = game.ReplicatedStorage.ChangePlayerTeam

TeamChangeEvent.OnServerEvent:Connect(function(player, teamName)
	player.Team = game.Teams:FindFirstChild(teamName)
	game.Players.PlayerAdded:connect(function(Player) 
    	Player.CharacterAdded:connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
			if Humanoid then
				Humanoid.Health = 0
			end
		end)
	end)
end)

Basically I have a menu for choosing teams The script detects when the RemoteEvent in ReplicatedStorage has been fired off by a detect team change localscript and changes the player's team to what button they clicked. Normally this script would work without the following lines:

game.Players.PlayerAdded:connect(function(Player) 
    	Player.CharacterAdded:connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		if Humanoid then
			Humanoid.Health = 0

What I want this script to do is kill the player after they changed teams from clicking the correspondant team button they have chosen, though it isn't working. What's wrong with it?

6 comments

0

Do you get any errors in the output?

0

It expected an end to close the function at line 3, though the script still doesn't work when I put another end

0

You never actually fire the server in any of the scripts

0

As I've already mentioned I have a working localscript that DOES fire the event, though when I put in those mentioned lines it breaks the script for some reason.

0

You could just get rid of everything(not the first function), but the team change line, and the humanoid.Health = 0 line. It just changes your team and then kills you. Oh., and do player.Character.Humanoid.Health = 0. Since if they are clicking it, they have a humanoid and you dont have to wait for it

0

Thanks for the help! This worked by just getting the player's humanoid and setting the health.