Team not Changing on Death

I am making a round based game, and I have two teams: Lobby and Game. They should be pretty self explanatory. So anyways, I have a LocalScript placed under StarterGui that is supposed to change the player’s team on death, but it does not.

I’m pretty sure the problem is function(___). I’m not sure which object’s perspective it’s coming from, and I’ve tried the player, character, and humanoid.

Can you help me write a functional script that changes the player’s team on death? If possible, let me know in a post!

1 Like

Can you show us the script you currently have?

1 Like

You should never try to change team on the client side (local script). You should also provide your current code so people can help you on identifying and solving the problem.

3 Likes

Show you’re code so we can see what’s wrong. Also, teams cannot be changed from the client.

I have tried many times. Which code attempt do you want to see?

Changing the team is not replicated from the client, so any change you make will either be rejected or only local to that one player.

As MrOutput wrote, you should not be doing this on the client (in a LocalScript). This should be done from the server (Script).

1 Like

You could make a script in server script service like this.

    Player.CharacterAdded:connect(function(Character) 
      repeat wait() until Character:FindFirstChild("Humanoid") ~= nil
       Character.Humanoid.Died:connect(function() 
         if Player.TeamColor == game.Teams.Game.TeamColor then
      Player.TeamColor = game.Teams.Lobby.TeamColor 
    end
   end)
 end)
end)

This will change the player’s team to Lobby when they die.
Hope it helps you out.

I was able to fix the problem with your help. Here’s the code I wrote that worked:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterRemoving:Connect(function()
		plr.Team = game.Teams.Lobby
	end)
end)

Thanks for the help!

This is in a normal script.