Annoying Humanoid Problem (A Character Doesn't Change Correctly)

I know there have been topics on this before like: Getting error "LoadAnimation requires the Humanoid object to be a descendant of the game object" despite waiting for Character, but I either can’t use them for my script or they don’t make sense to me at all. I have made a custom character setup for my game and I always get this annoying Humanoid is not a descendant of game error. I have tried many things, but have failed to do so. Here is my script for changing the default character:

Script
local function CharacterLoop(Player)
	if Player.Team.Name == "Luigi" then
		Player:LoadCharacter()
		local Character = Player.Character

		local NewCharacter = game:GetService("ServerStorage"):WaitForChild("Luigi"):Clone()
		NewCharacter.Parent = game.Workspace
		NewCharacter.Name = Player.Name
		Player.Character = NewCharacter

		Character = Player.Character
		
		local CameraFixer = script.CameraFixer:Clone()
		CameraFixer.Disabled = false
		CameraFixer.Parent = Player:WaitForChild("PlayerGui")
		-- more of the code continuing
		local Character = Player.Character
		
		local Humanoid = Character:WaitForChild("Humanoid")
		Humanoid.Died:connect(function()
			wait(5)
			CharacterLoop(Player)
		end)
    end
    game.Players.CharacterAutoLoads = false

    local function OnPlayerAdded(Player)
	    CharacterLoop(Player)
    end

    game.Players.PlayerAdded:connect(OnPlayerAdded)
	    for _,Player in pairs(game.Players:GetPlayers()) do OnPlayerAdded(Player) end

What I am mainly frustrated about is that the character doesn’t change if you are on the Luigi team, there is also an animation problem with every regular roblox character, but that is not a big problem right now. Other then that everything else works perfectly, changing to the boo custom models and their animations/movements.

Any help is very appreciated! :grin:

This wouldn’t be an issue if the Avatar Loading Event Ordering Improvements update, which was announced on April 19th, wasn’t delayed for nearly half a year.

That aside, you have a few issues from your own end to fix such as how you’ve stuffed your entire code right into the CharacterLoop function. This includes having the function listen to PlayerAdded which can end up spawning several instances of your code. The code that checks for added players needs to be divorced from the character changing handler.

I ended up fixing it, by changing the code up a little bit and messing with other scripts that got in the way of this. Thanks for the help @PostApproval!