Would I go about copying everything in the player's camera into the viewportframe like this?

I am planning on making a flashbang, and I was wondering how I would copy everything in the player’s camera into a viewportframe optimally, instead of copying everything from the workspace, would this be more optimal.

local worldPoint = v.Position
			local vector, inViewport = camera:WorldToViewportPoint(worldPoint)

Problem with this, is I would have to loop through the entire workspace anyway. How would I do this?

First of all, you need to set the viewport current camera to the workspace current camera by using a local script, like this:
ViewportFrame.CurrentCamera = workspace.CurrentCamera

Then, you need to duplicate everything from the workspace and put those into the viewportframe. Note: Some models, like the player character, have their archivable set to false. This means you can’t clone them. If you want to clone the player’s character, you need to copy all the children inside the model instead, not the model itself.

After that, you need to check if any parts move or rotate and if so, update the duplicated part’s position and rotation to match the real one. You also need to make sure if any parts get added or deleted and update those into the viewportframe. That’s all. :slight_smile:

This was copied from another topic. I don’t want it to keep moving, I want it to copy for one frame and I don’t want to loop through the entirety of workspace while constructing the viewport frame

Yes it was.

Maybe someone else can help you with that, I’ve never really worked with viewports to that extent, I’m sorry.

I made a similar topic to this, however there was really no way of getting all parts in the camera’s viewport.

However, I got multiple suggestions from that topic, and I personally like this the most

Attaching a sphere infront of the camera, then use workspace:GetPartsInPart for that. However, it may miss very far objects.

1 Like

Interesting, do you have an idea on how big this sphere would be once I CFrame it to the camera’s position?