Viewport frame not working

Hello everyone, Im having a slight issue with the UI im making. For some reason the viewport frame doesn’t work.

When I click on the property, as usual the mouse thing appears to let you click the model you want to put in the frame. I click the model and for some reason the framee stays empty.

Thanks for reading.

1 Like

Can you please provide more context as to what is going on? It will help us better understand your problem and find a solution.

2 Likes

I dont know what else I can provide

Make sure the model is inside the ViewportFrame, the CurrentCamera property in the ViewportFrame is set, and the camera in the ViewportFrame (make sure it has one!) can see the model.

It might be helpful to get a plugin that can automate some of this for you, such as Viewport Generator by Zomebody.

3 Likes

Can you please tell me what do you exactly mean by “the camera in the ViewportFrame can see the model.”

Just like the player’s normal Camera in Workspace, the Camera in a ViewportFrame has a CFrame property. This controls the position and rotation of the “eye” that is seeing stuff.

If your eye (camera) is pointing backwards and the object you want to be displaying in the ViewportFrame is forwards, then the object won’t be visible in the ViewportFrame because the eye (camera) is looking in the opposite direction and can’t see it. Similarly, if the eye (camera) is position really far away from the object then it won’t be visible because it is too small or out of frame or whatever.

So you need to make sure that object you want to display is in front of the camera (or vice versa, that the camera is looking at the object), and that they are close enough / aligned to each other so the object is in frame and displays at a reasonable size.

Here is a code example:

-- the normal identity cframe positioned at 0, 0, 0
-- and looking in the direction of -Z axis
camera.CFrame = CFrame.new(0, 0, 0)

-- then we move the model to be 20 studs away in the
-- direction camera is looking so that it is visible
model:PivotTo(CFrame.new(0, 0, -20))

-- OR, a slightly more advanced version:

-- make the model be 20 studs in front of the camera,
-- no matter where the camera is or where it's looking
model:PivotTo(camera.CFrame * CFrame.new(0, 0, -20))
1 Like