How to switch character to a new character?

i was try to make this swap switch a new Character without destroying the old one when a player touches a new character (illusion) it’s should destroy the new character and character return to their old character

local function Clone(Player, Character)
	if game.Workspace:FindFirstChild(Character.Name) then
		Character.Archivable = true
		local NewCharacter = Character:Clone()
		local PlayerRoot = Character:FindFirstChild("HumanoidRootPart")
		
		if NewCharacter:FindFirstChild("HumanoidRootPart") then
			NewCharacter.PrimaryPart = NewCharacter.HumanoidRootPart
		elseif NewCharacter:FindFirstChild("Torso") then
			NewCharacter.PrimaryPart = NewCharacter.Torso
		end
		
		if PlayerRoot and NewCharacter.PrimaryPart then
			local SpawnOffset = Vector3.new(5,0,5)
			NewCharacter:SetPrimaryPartCFrame(PlayerRoot.CFrame + SpawnOffset)
		end
		
		Character.Archivable = false
		NewCharacter.Name = "Mirage_" .. Character.Name .. "_Clone"
		NewCharacter.Parent = game.Workspace
		
		for _, v in ipairs(NewCharacter:GetDescendants()) do
			if v:IsA("Accessory") then
				if v.Name == "hand stick" or v.Name == "Background" or v.Name == "mirage effect" then
					v:Destroy()
				elseif v.Name == "flute" then
					if v:FindFirstChild("Handle") and v.Handle:FindFirstChild("FLUTE FOX") then
						v.Handle["FLUTE FOX"].Transparency = 0
					end
				end
			end
		end
		
		for _, Part in ipairs(NewCharacter:GetDescendants()) do
			if Part:IsA("BasePart") then
				Part:SetNetworkOwner(Player)
			end
		end
		
		local bSwap = false
		Player.PlayerGui.MirageGui.Mirage.Visible = true
		Player.PlayerGui.MirageGui.Mirage.MouseButton1Click:Connect(function()
			if not bSwap then
				bSwap = true
				--Swap to New Player and do not make it reset the old player so it can swap back (bSwap = false) to the old player	
			elseif bSwap then
				
			end
		end)
	end
end

if you figure this issue out that would be very helpful!
Thank you!

1 Like

Try putting print statements here, and see if it is able to find them:

if NewCharacter:FindFirstChild("HumanoidRootPart") then
			NewCharacter.PrimaryPart = NewCharacter.HumanoidRootPart
            print("found root part")
		elseif NewCharacter:FindFirstChild("Torso") then
			NewCharacter.PrimaryPart = NewCharacter.Torso
            print("found torso")
		end
1 Like

it found Root Part but didn’t goes into the NewCharacter
image

Hmm yes, that is what I expected. When cloning the character, it seems the root part won’t simply load into the new character from the clone command.

Maybe try :WaitForChild('HumanoidRootPart') instead of FindFirstChild("HumanoidRootPart"). If that does not work, maybe try adding a task.wait(0.1) just to check after the local NewCharacter = Character:Clone() line.

just check it does the same thing and if i use Player.Character = NewCharacter it kills the old player

any Solution yet???

Just to clarify, are you saying the root part is found, but it is not loaded into the new character? If so, where is it located?

Yes it’s not loading into the new character