Trouble with trying to get team avatars

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I’m trying to make it where if you’re in the red team you get red’s avatar, as if your in the blue team you get blue’s avatar.

  2. What is the issue? The characters do not get replaced with the current character. At the first attempt but after the character resets it prints “Maximum event re-entrancy depth exceeded for Player.CharacterAdded”

  3. What solutions have you tried so far? I looked at the forums and tried some solutions but it still wouldn’t spawn. I’ve tried looking at tutorials but there aren’t many. I’ve also tried to find a solution for Maximum event re-entrancy depth exceeded for Player.CharacterAdded but they weren’t of any use.

local ServerStorage = game:GetService("ServerStorage")

local characters = ServerStorage.CustomCharacter.Default

game.Players.PlayerAdded:Connect(function(player)
	print("000")
	player.CharacterAdded:Connect(function(character)
		print("311")
		if player.TeamColor == "Electric blue" then -- doesn't get past here
			print(111)
			local newChar = characters:Clone()
			newChar.Name = player.Name

			newChar.Parent = workspace
			player.Character = newChar

		elseif player.TeamColor == "Dusty Rose" then
			print(211)
			local newChar = characters:Clone()
			newChar.Name = player.Name

			newChar.Parent = workspace
			player.Character = newChar
		end
	end)
end)

I’m not getting any errors at first which is why I have the prints to see where the code stops.

1 Like

I’ve never heard of that error, neither have I seen it occur in any game.

Can you elaborate a bit further on what happens exactly?

Unless you’re doing a rig which isn’t R6/R15 anymore, wouldn’t :ApplyHumanoidDescription() be simpler here?

Here’s some extra info about that:

1 Like

Yes, so basically the character loads it doesn’t change its character but once the character resets or dies the camera will break and it will cause that error.

Is this a local or server script?

This occurs when you are setting a new character to the player.Character, I had this issue before and I believe I can explain

whenever you set a new player.Character, it will replace the character but then fire the player.CharacterAdded listening function–if you see where this is going its simply looping, that is why you get that maximum entry exceeded thing, it fired so many times it reached the maximum and I believe stopped.

local RespawnTable={}

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)

		--This here is needed as character added fires multiple times when activating morph changes, needs to stay here to prevent mass cloning
		if table.find(RespawnTable, player.Name) then
			table.remove(RespawnTable, table.find(RespawnTable, player.Name))
			return
		end


		table.insert(RespawnTable, player.Name)

--change player.Character and I utilized functions to set up  new morph

      end)
end)

this is how i fixed the issue I had anyway, let me know if this fixes your issue @VoidPan_Dev

I’m starting to get an issue attempt to index nil ‘WaitForChild’ for trying to get the default avatars. Also is this in a local or regular script?

Its in a server script

can you show your updated code? I don’t see waitforchild within the original.

Never mind I just change the script from local to server. My bad. Also when It says change player.Character and I utilized functions to get up new morph that means I put the

		elseif player.TeamColor == "Dusty Rose" then
   		print(211)
   		local newChar = characters:Clone()
   		newChar.Name = player.Name

   		newChar.Parent = workspace
   		player.Character = newCharacter

into that spot right?

put this at the start of the characteradded function and everything else bellow.

Would need to be a server script otherwise the changes won’t replicate.