Cloned character gets instantly destroyed when inserted into a viewport frame

very self explanatory

parenting the character to workspace just doesn’t viewporet anything

:////

local function CreatePlayerViewport()
	char.Archivable = true
	-- clone the character 
	local clonedChar = char:Clone()
	clonedChar.Parent = playerViewportFrame
	print(clonedChar.Parent)
	--clonedChar:PivotTo(viewportPart.CFrame)

	-- delete unnecessary stuff from it (like animations)
	for _, descendant in clonedChar:GetDescendants() do
		if descendant:IsA("LocalScript") or descendant:IsA("Animator") then
			descendant:Destroy()
		end
	end
	
	-- get root part and create camera
	local clonedRootPart: BasePart = clonedChar:FindFirstChild("HumanoidRootPart")
	local viewportCamera = Instance.new("Camera")
	viewportCamera.Name = "ViewportCamera"
	
	-- clear previous content from viewport if exists
	playerViewportFrame:ClearAllChildren()
	
	-- set viewport camera parent
	viewportCamera.Parent = playerViewportFrame
	playerViewportFrame.CurrentCamera = viewportCamera
	viewportCamera.CameraSubject = clonedChar
	
	---- set camera cframe
	local positionToBeAt = clonedRootPart.Position + Vector3.new(0, 1.5, -3) -- 1.5 studs above root part and 3 studs infront of it
	viewportCamera.CFrame = CFrame.new(positionToBeAt, clonedRootPart.Position)
end

You are using playerViewportFrame:ClearAllChildren() after the clone character is cloned into the viewport which deletes it.

1 Like

oml :man_facepalming:

i forgot about that line entirely :sob:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.