Character not rendering in a viewpoint

So I have this script to get the players character and render it in a viewport

local viewPort = script.Parent:WaitForChild("PlayerCharacterRenderer")
local player = game.Players.LocalPlayer
local character = player.Character
character:WaitForChild("HumanoidRootPart")

character.Archivable = true
local DuplicateCharacter = character:Clone()
character.Archivable = false

local Camera = Instance.new("Camera", script)
Camera.CFrame = game.Workspace.PlayerOutfitRenderer.CameraPart.CFrame
viewPort.CurrentCamera = Camera

DuplicateCharacter.Parent = workspace
wait(1)
DuplicateCharacter.Parent = viewPort
DuplicateCharacter.HumanoidRootPart.CFrame = game.Workspace.PlayerOutfitRenderer.PlayerCharacterPosition.CFrame

When I run it everything works fine, the character get’s cloned and parent to the viewport but the character doesn’t actually render in the viewport. If I put the character in the workspace and then back into the viewport it starts to work. I’ve tried replicating that with the script but nothing works. How can I fix this?

Try setting the primary part CFrame to CFrame.new(0,0,0)

Could you explain why I have to do that? What’s the difference between using :SetPrimaryPartCFrame and directly setting the primary part’s CFrame?

Oh no, I meant using :SetPrimaryPartCFrame. :MoveTo would work as well but it requires a Vector3 instead of a CFrame.

You should try that as the default camera’s CFrame is CFrame.new(0,0,12), therefore the character would be in the camera’s FOV.

Yeah that’s what I did

local viewPort = script.Parent:WaitForChild("PlayerCharacterRenderer")
local player = game.Players.LocalPlayer
local character = player.Character
character:WaitForChild("HumanoidRootPart")

character.Archivable = true
local DuplicateCharacter = character:Clone()
character.Archivable = false

local Camera = Instance.new("Camera", script)
Camera.CFrame = game.Workspace.PlayerOutfitRenderer.CameraPart.CFrame
viewPort.CurrentCamera = Camera
DuplicateCharacter:WaitForChild("HumanoidRootPart")

DuplicateCharacter:SetPrimaryPartCFrame(game.Workspace.PlayerOutfitRenderer.PlayerCharacterPosition.CFrame)
DuplicateCharacter.Parent = viewPort

But why does this work and what I did before doesn’t?

It’s because the character was likely out of the camera’s field of view when it was added as a child to the viewport.

It’s similar to how if you place an item into ReplicatedStorage then take it back out, it will maintain the position it had before putting it in. Even if it’s not visible.