How to put a model in a viewport frame?

This is what I have so far, but no cigar. I’m not quite sure how to achieve this. I just want to have the viewport frame basically face towards a model in the workspace. Or just face a model (that doesn’t have to be in the workspace)


local model = game.Workspace:WaitForChild("Test")
local viewportFrame = script.Parent

local camera = Instance.new("Camera")

camera.Parent = viewportFrame

-- Set the Camera's properties to focus on the model

camera.CameraSubject = model

camera.FieldOfView = 50

viewportFrame.CurrentCamera = camera

Have you tried parent that model into your viewportFrame? You may also need to set its PrimaryPart using :SetPrimaryPartCFrame(). Let me know how it goes.

Parenting doesn’t do anything
///////

There is something that you make need to check

  1. Is your viewportFrame being parented inside guis? (ie. SurfaceGui, ScreenGui)?
  2. Parenting new camera into that viewportFrame, also set the position of the camera.
  3. Parenting models into that viewportFrame, make sure that their position can be seen by the camera above.

I’m trying to do this: https://gyazo.com/dcc41aaaae259051ff7cc14071d57320

And this doesn’t seem to work.

Is the model showing up in you game? Or it doesn’t show at all?

The issue is you can’t copy paste a camera, it will delete itself once you run the game.

I have figured out how to put my viewport frame on the model. But I can’t figure out how to make a new camera for the right position.

What is the method that you use to set your new camera position? try viewportCamera.CFrame = CFrame.new(Vector3.new(0,0,0))

Also please check if your camera is inside a viewportFrame and that viewportFrame is under GUI.

Note: use Z-axis to indicate how far your camera from the screen. X-Axis for left and right.