Custom Team Characters

Team characters not working

local ServerStorage = game:GetService("ServerStorage")

local chickenColor = BrickColor.new("Gold")
local butcherColor = BrickColor.new("Bright red")

local characters = ServerStorage.Characters

game.Players.PlayerAdded:Connect(function(player)
	
	player.CharacterAdded:Connect(function(character)
		
		if player.TeamColor == chickenColor then
			
			local newChar = characters.Chicken:Clone()
			newChar.Name = player.Name
			
			character.Parent = workspace
			character = newChar

		elseif player.TeamColor == butcherColor then
			
			local newChar = characters.Butcher:Clone()
			newChar.Name = player.Name
			
			character.Parent = workspace
			character = newChar
		end
	end)
end)

1 Like

Try this

local ServerStorage = game:GetService("ServerStorage")

local chickenColor = BrickColor.new("Gold")
local butcherColor = BrickColor.new("Bright red")

local characters = ServerStorage.Characters

game.Players.PlayerAdded:Connect(function(player)
	
	player.CharacterAdded:Connect(function(character)
		
		if player.TeamColor == chickenColor then
			
			local newChar = characters.Chicken:Clone()
			newChar.Name = player.Name
			
			newChar.Parent = workspace
			player.Character = newChar

		elseif player.TeamColor == butcherColor then
			
			local newChar = characters.Butcher:Clone()
			newChar.Name = player.Name
			
			newChar.Parent = workspace
			player.Character = newChar
		end
	end)
end)

Okay that works but there is an error when I run this.

Maximum event re-entrancy depth exceeded for Player.CharacterAdded

How could I get rid of this?

That error happens when the Player.CharacterAdded runs too fast (probably due to player resetting character too quickly?) I don’t have a clue on how to fix that.

It happens because you’re setting the player’s character too soon, add a yield before doing so.

2 Likes