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?
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.