Render a camera view in a viewport frame

Hello.
Since I am pretty bad with viewort frame, I decided to open this topic.
So i’m trying to render a camera view in a viewport frame (something like in the image below)


But from what I’ve seen so far, only the player character or a part is rendered. I know that it has a “CurrentCamera” property but I don’t really know how to use it. Any idea?

4 Likes

What is the issue? Are you trying to mimic/construct this picture? It would be best if you show your code and picture of your result

The result is a blank white square, I am here to see if you have some idea of what can I use to achieve the result of this photo montage

Did you put a WorldModel inside of the viewport frame?

https://gyazo.com/3542e2615b3192d61f59512e62598bee
https://gyazo.com/3d4f7df0ae7285453c4513db9a6e3392

After a little bit of playing around I’ve managed to get this working. I’d like to give thanks to @XAXA for their SkyBox model (which can be used to emulate skyboxes in WorldModels).

Here’s the script I wrote.

local run = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
player.CharacterAppearanceLoaded:Wait()

local clientCamera = workspace.CurrentCamera
local gui = script.Parent
local viewportFrame = gui:WaitForChild("ViewportFrame")
local worldModel = viewportFrame:WaitForChild("WorldModel")
local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame

task.wait(1)

character.Archivable = true
local characterClone = character:Clone()
characterClone.Parent = worldModel
characterClone.Humanoid.NameDisplayDistance = 0
characterClone.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Subject

run.RenderStepped:Connect(function()
	characterClone:PivotTo(character:GetPivot())
	viewportCamera.CFrame = clientCamera.CFrame
end)

Here’s the model file if you’d like to see how everything is organised:
model.rbxm (8.2 KB)

11 Likes

Okay, so I know this is a somewhat old post, but I was wondering, after a while the model stops working… Any reason why? I am a beginner scripter/GUI designer and would really appreciate the reply!

Thanks,
Theo

have you found it out? i still have the problem