Help with ViewportFrames

Hello!

I’m quite new to viewportframes and CFrame scripting. I am trying to make a camera system, where the view of a camera (in game) is visible on a GUI. Online, all I can find is people scripting stores for simulators where a singular item is displayed. I need everything the in-game camera sees to display on the GUI.

Images can be seen below here which show the preview window, and the camera where the footage from the camera will be displayed live. Any help would be appreciated! :smile:

Screenshot 2023-02-16 at 15.15.03
Screenshot 2023-02-16 at 15.11.42

I would recommend reading up first:

The main issue with this is that you’ll have to determine how you want to capture what’s “in-scene”. I wouldn’t recommend cloning the entire workspace into a viewport. The other issue is that you’ll have to actively track any in-scene unanchored part in order to update the cloned part within the viewport. Lastly, it’s important to realize that viewports render at a lower quality and doesn’t even support transparency outside of 0 and 1.

I’m not too sure how to render MULTIPLE things inside a viewport frame though, that’s the main thing. I’m mostly focused on rendering the floor and the players. I’ll have a read through those though, thanks!

Any instances inside of the viewport will be rendered within the viewport. However, keep in mind that their worldspace is relative to the actual world space, which does make it easy for this sort of situation. You just need to assign a new camera to the viewport’s CurrentCamera property and set it’s CFrame to that of the camera (same position and facing the same direction).

I’m so sorry, I’m sort of new to scripting after a long break. Where exactly do I put the new camera?

The new camera can be anywhere really, but I’d probably put it inside of the viewport so it can be garbage collected at the same time.

By “viewport” I’m assuming you mean the viewportframe? Or is there a separate item called “viewport”? This is what I have in StarterGui so far:
Screenshot 2023-02-16 at 15.58.59

I do indeed mean the ViewportFrame.

You would need to clone everything and this would get quite laggy quite quickly.

You wouldn’t need to clone “everything”, only the instances that are “in-scene”. This can be done with a simple Spacial Query. However, I would highly recommend also optimizing it. One example would be not rendering when the player isn’t looking at it. I’m not sure if Roblox handles that automatically or not, but considering they don’t seem to do that with normal UI elements are off screen, I doubt they’d do it here either.

1 Like