Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to set CFrame of the ViewportFrame camera to the CFrame of the main camera?

Hello all, so today I am trying to match up the ViewportFrame camera with the main camera by setting it's CFrame. I have code attached. The script is the child of the ViewportFrame.

wait(3)

while 2+2==4 do

local viewportFrame = script.Parent

local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame

local camera = workspace.CurrentCamera
local cameraCFrame = camera.CFrame
local viewCFrame = viewportCamera:GetRenderCFrame()

viewportCamera.CFrame = CFrame.new(Vector3.new(cameraCFrame))
print(viewCFrame)
wait(0.1)


end

Thank you! Any help is appreciated.

1 comment

0

Sorry if my code is messy. I am new to Lua!

1 answer

✓ Accepted answer

It's actually quite simple! You just need to set the ViewportFrame's CurrentCamera to the current camera in workspace with a LocalScript.

script.Parent.CurrentCamera = workspace.CurrentCamera --Set the CurrentCamera of the ViewportFrame as the CurrentCamera in workspace

1 comment

0

Thanks! Way easier than expected!

This discussion is preserved as it was. New answers, comments, and votes are closed.