Cameras Help. Need help with positioning the target

I was wondering what is the best way to set a camera and a target to the viewport frame, I tried the basic okay lets just put the cameras target to the object and then put the object into the camera,

but I came to and issue, the position of the the camera how would I make the camera and the object a good position without needing to manually try to fit the object in to the camera and then just put that the objects position is the position where it will fit to the camera, but it doesn’t work the same for every object so any solutions?

Something like this

local model = --path to model
local modelSize = model:GetExtentsSize()

model:SetPrimaryPartCFrame(CFrame.new(0 , 0 , 0))
camera.CFrame = CFrame.new(0 , 0 , 0) * CFrame.new(modelSize)
--i might have miss spelled lookAt
camera.CFrame = CFrame.lookAt(model.PrimaryPart.Position , model.PrimaryPart.Position)

Did not work for me, here is the code if you can help

local ItemMesh = Meshes:FindFirstChild(v)
			local ItemMeshSize = ItemMesh:GetExtentsSize()
			ItemMesh:SetPrimaryPartCFrame(CFrame.new(0 , 0 , 0))
			
			local itemgui = game:GetService("ReplicatedStorage"):FindFirstChild("Gui"):FindFirstChild("Template"):FindFirstChild("Item"):Clone()
		itemgui.Name = v
		itemgui.ItemName.Text = v
			local itempic = itemgui:FindFirstChild("Camera")
			itempic.CFrame = CFrame.new(0 , 0 , 0) * CFrame.new(ItemMeshSize)
			itempic.CFrame = CFrame.lookAt(ItemMesh.PrimaryPart.Position , ItemMesh.PrimaryPart.Position)
			ItemMesh.Parent = itempic
			itempic.CameraSubject = ItemMesh
			ItemMesh.Parent = itempic
			
			itemgui.CurrentCamera = itempic
			itemgui.Parent = InventoryGui

No need for these

ItemMesh.Parent = itempic
itempic.CameraSubject = ItemMesh
ItemMesh.Parent = itempic

The item needs to be in a viewport frame before doing all of this and at the end set viewport.CurrentCamera to the camera we setup, so if this is the viewport frame

itemgui.Parent = InventoryGui

It needs to be at the top

			local ItemMesh = Meshes:FindFirstChild(v)
			
			
			
			local itemgui = game:GetService("ReplicatedStorage"):FindFirstChild("Gui"):FindFirstChild("Template"):FindFirstChild("Item"):Clone()
			local itempic = itemgui:FindFirstChild("Camera")
			ItemMesh.Parent = itemgui
			itemgui.CurrentCamera = itempic
			itemgui.Parent = InventoryGui
			
			local ItemMeshSize = ItemMesh:GetExtentsSize()
			ItemMesh:SetPrimaryPartCFrame(CFrame.new(0 , 0 , 0))
			
			
		itemgui.Name = v
		itemgui.ItemName.Text = v
			
			itempic.CFrame = CFrame.new(0 , 0 , 0) * CFrame.new(ItemMeshSize)
			itempic.CFrame = CFrame.lookAt(ItemMesh.PrimaryPart.Position , ItemMesh.PrimaryPart.Position)

Näyttökuva 2022-08-03 132455

It doesn’t show up on the viewportframe the object the things are right, but its not showing so I would guess its at a wrong position , how would I get it to be at the front of the camera?

this should be at the end, dont try to use a camera that already exists

Instance.new("Camera")

and no need to set its parent to the viewport

local ItemMesh = Meshes:FindFirstChild(v)
			
			
			
			local itemgui = game:GetService("ReplicatedStorage"):FindFirstChild("Gui"):FindFirstChild("Template"):FindFirstChild("Item"):Clone()
			local itempic = Instance.new("Camera")
		
			
			itemgui.Parent = InventoryGui
			
			local ItemMeshSize = ItemMesh:GetExtentsSize()
			ItemMesh:SetPrimaryPartCFrame(CFrame.new(0 , 0 , 0))
			
			
		itemgui.Name = v
		itemgui.ItemName.Text = v
			
			itempic.CFrame = CFrame.new(0 , 0 , 0) * CFrame.new(ItemMeshSize)
			itempic.CFrame = CFrame.lookAt(ItemMesh.PrimaryPart.Position , ItemMesh.PrimaryPart.Position)
			
			
			itemgui.CurrentCamera = itempic

I don’t think the Model is showing up on the viewport, are you sure that is the way to do it?

Try printing the CFrames l, check if they are correct

ItemMesh is just 0, but the itempic is 1.60830426, 5.18458462, 0.54369545, 1, 0, 0, 0, 1, 0, 0, 0, 1

Idrk why it doesn’t work, when i wake up, ill look back to it!