Team changer not working

I’ve got a script that changes teams for the player. It goes off a table, and when the player hits a button the event fires with the name of the team they want to join. This is the server script:

game.ReplicatedStorage.ChangeTeam.OnServerEvent:Connect(function(player, team)
	print(team)
	if team == "Class D" then
		player.TeamColor = BrickColor.new("Deep orange")
	elseif team == "Scientific Department" then
		player.TeamColor = BrickColor.new("Really blue")
	elseif team == "Ethics Committee" then
		player.TeamColor = BrickColor.new("Shamrock")
	elseif team == "Foundation Personnel" then
		player.TeamColor = BrickColor.new("Medium stone grey")
	elseif team == "Manufacturing Department" then
		player.TeamColor = BrickColor.new("Eggplant")
	end
	wait(5)
	player:LoadCharacter()
end)

The team doesn’t change, however the player’s character loads. Help’s appreciated. Thanks.

1 Like

Try making sure the player has a team before trying to change it( so add a check to see what the player team is by doing print(player.Team.Name) also, you can set team by simply setting the team name to whatever name the team is. Instead of relying on TeamColor. And I believe the default team is “Neutral”.

Try change

player.TeamColor = BrickColor.new

To

player.Team = game.Teams[team]
1 Like

I have no idea why I didn’t try that. Thank you!