Viewport not showing the model

function createItem(item)
	local button = Instance.new('ImageButton')
	button.AnchorPoint = Vector2.new(0.5, 0.5)
	button.BackgroundTransparency = 1
	button.Name = item.Name
	button.Image = 'rbxassetid://295943248'
	button.ScaleType = 'Slice'
	button.SliceCenter = Rect.new(10, 10, 20, 20)

	local viewport = Instance.new('ViewportFrame')
	viewport.AnchorPoint = Vector2.new(0.5, 0.5)
	viewport.Size = UDim2.new(0.8, 0, 0.8, 0)
	viewport.Position = UDim2.new(0.5, 0, 0.5, 0)
	viewport.BackgroundColor3 = Color3.new(1, 1, 1)

	local camera = Instance.new('Camera')
	viewport.CurrentCamera = camera
	
	local clone = item:Clone()
	clone.Parent = viewport

	local cameraPosition = Vector3.new(3, 3, 3)
	camera.CFrame = CFrame.new(cameraPosition, clone.PrimaryPart.Position)
	
	local aspectRatio = Instance.new('UIAspectRatioConstraint')
	aspectRatio.AspectType = 'ScaleWithParentSize'
	
	camera.Parent = viewport
	viewport.Parent = button
	aspectRatio.Parent = button
	button.Parent = buttons
end


The ViewPort is inside the grey box and the model has a bright green part so I should be able to see it. Any help?

It’s my first time using ViewportFrames, so if anyone has any good troubleshooting methods then please advise me :smiley:

3 Likes

Change the position of the “clone” to 0,0,0 and see if it works.

clone:SetPrimaryPartCFrame(CFrame.new(0,0,0))
1 Like
local dist = 10 -- distance of camera from model

camera.CFrame = CFrame.new(clone.PrimaryPart.Position + clone.PrimaryPart.CFrame.LookVector * dist, clone.PrimaryPart.Position)