Viewport Frame Model not showing up?

Hello developers. I made this post because my viewport frame isn’t showing the models I want it to. From a script, I am cloning all of the models in a certain folder, and then showing them in a viewport frame. However, it is not working. (ViewItem is a model under the viewport frame.)

for i, v in pairs(builds:GetChildren()) do
			if v:IsA("Model") then
				local newViewPort = viewPortFrame:Clone()
				newViewPort.Visible = true
				newViewPort.Parent = buildsFrame
				local viewPortBuild = v:Clone()
				viewPortBuild.Parent = newViewPort.ViewItem

				local newCam = game.Workspace.CurrentCamera:Clone()
				newCam.Parent = newViewPort

				newViewPort.CurrentCamera = newCam
				newViewPort.CurrentCamera.CameraType = Enum.CameraType.Scriptable
				newCam.CameraSubject = viewPortBuild

			end
		end
1 Like

The viewportframe can only see what the camera sees, so cframe the camera so it can view the WorldModel.

Can you give me an example on how to do this?

1 Like

Can anyone please help me? I am stuck on this

Hey, here’s a basic example of how you can show a model in a ViewPort frame:

-- First setup a camera in your ViewportFrame
local viewport = viewPortFrame
local ViewportCamera = Instance.new('Camera', viewport) -- let's make a new camera under the viewportframe
ViewportCamera.CameraType = Enum.CameraType.Scriptable
ViewportCamera.FieldOfView = 10 -- change accordingly
viewport.CurrentCamera = ViewportCamera

-- Then put your Model "ViewItem" in the ViewPort and adjust your camera
local model = ViewItem
model:SetPrimaryPartCFrame(CFrame.new(0, 0, 0))
model.Parent = viewport```

Make sure the model is in the correct position. The models could have different positions and therefore are not showing up.
Use model:PivotTo(CFrame.new(CFRAME POS HERE)) to achieve this.

Hello, right now the objects look like this, and also, every model is a different size, so is there a way I can make this look better (because it doesn’t look very good right now)
image

1 Like

Hey, you can try to use

local modelOrientation = 45
model:SetPivot(CFrame.new(0, 0, 0)*CFrame.Angles(0, math.rad(modelOrientation), 0))

and set the camera CFrame by using

local camDistance = 3
viewportCam.CFrame = CFrame.new(Vector3.new(camDistance, camDistance, camDistance), model:GetPivot().Position) 
-- replace viewportCam with the name of the variable storing the viewport camera/viewport.CurrentCamera

This will make it so the model in the viewport frame is farther from the camera and is orientated, and you can customize this using the variables or further modifying it the code.

Hey did you mean :GetPivot() instead of :SetPivot(), either way, this does not work.

Almost none of them are there, and these are the ones that are:

can you send a screenshot of how the models should look (so a screenshot of the models)

Also, can you resend the script with edits

Yes, here is an example model. (There are all different sizes.)

Also, what do you mean by a script with edits?

Like can you send the script with the edits applied from the posts?

for i, v in pairs(builds:GetChildren()) do
			if v:IsA("Model") then
				local newViewPort = viewPortFrame:Clone()
				newViewPort.Visible = true
				newViewPort.Parent = buildsFrame
				
				local viewPortBuild = v:Clone()
				viewPortBuild.Parent = newViewPort
				
				local modelOrientation = 45
				viewPortBuild:GetPivot(CFrame.new(0, 0, 0)*CFrame.Angles(0, math.rad(modelOrientation), 0))

				local newCam = Instance.new("Camera")
				newCam.Parent = newViewPort
				newCam.CameraType = Enum.CameraType.Scriptable
				newCam.FieldOfView = 10
				newViewPort.CurrentCamera = newCam
				newCam.CameraSubject = viewPortBuild
				
				local camDistance = 3
				newCam.CFrame = CFrame.new(Vector3.new(camDistance, camDistance, camDistance), viewPortBuild:GetPivot().Position) 
				
				viewPortBuild:PivotTo(CFrame.new(0, 0, 0))
			end
		end

Also, let me know if you need more code than that, though I doubt you will. (There is just the function and a few more lines that delete the viewports previously in the frame first)

Any help would be appreciated. (I am sorry for kinda spamming, I just really can’t get past this issue. I am very, very sorry)

This should be viewPortBuild:PivotTo(CFrame.new(0, 0, 0)*CFrame.Angles(0, math.rad(modelOrientation), 0)).

Still doesn’t look right, is it possible you could make an example on how to make it look good? I can revert you to a new post that I make since this one wasn’t active. Changing Viewport Field of View and Position based on size of model - #8 by BeardedNewbie