Why does this team morph code not work?

This is ment to detect when the player joins/respawns, and give them the proper clothing for their team.

local Players = Game:GetService("Players")
local Teams = Game:GetService("Teams")
local ServerStorage = Game:GetService("ServerStorage")
local RedTeam = Teams.Elves 
local BlueTeam = Teams.Winters 
local RedCharacter = ServerStorage.TeamCharacters.Elves.HumanoidDescription 
local BlueCharacter = ServerStorage.TeamCharacters.Winters.HumanoidDescription 

local function PlayerAdded(Player)
	local function OnCharacterAdded(Character)
		
		if Player.Team == RedTeam then
			Player:LoadCharacterWithHumanoidDescription(RedCharacter)
			
		elseif Player.Team == BlueTeam then
			Player:LoadCharacterWithHumanoidDescription(BlueCharacter)
			
		else
		
		end
	end

	Player.CharacterAdded:Connect(OnCharacterAdded)
end

Players.PlayerAdded:Connect(PlayerAdded)

Instead, it would spawn in multiple copys of my character. I don’t know why this is happening!!

It does not work because you are loading a player’s character when the player’s character is loaded. Instead, I believe that you can apply a description onto a character.

humanoid:ApplyDescription(description)

Not sure if this works though.

1 Like

Changed the code to

local Teams = game:GetService("Teams")
local ElvesCharacter = game.ServerStorage.TeamCharacters.Elves.HumanoidDescription 
local WintersCharacter = game.ServerStorage.TeamCharacters.Winters.HumanoidDescription 


game.Players.PlayerAdded:connect(function(Player)
	
	Player.CharacterAdded:connect(function(Character)
		wait(0.5)
		
		if Player.Team == Teams.Elves then
			Character.Humanoid:ApplyDescription(ElvesCharacter)
			
		elseif Player.Team == Teams.Winters then
			Character.Humanoid:ApplyDescription(WintersCharacter)
			
		end
		
	end)
	
end)

incase anyone is wondering