How to get viewport camera from local script?

I’m trying to copy the local players camera and transfer it to the viewport camera in a heartbeat connection.

However only a server script can access viewportframe’s cameras and only local scripts can access players local camera.

1 Like

are you sure? because (if your creating the camera in a script), i would recommend using a local script. if not, then the server cant even detect cameras because they are local only…

1 Like

image
This is how its set up and I tested both the script and local script.

When Im ingame In my player I don’t see a camera here, unless I’m in server mode.
image

This is the error I get:

Well there is an alternative way you can do this by just making a new part instance and coyping the CFrame of the viewport frames camera and setting it to the new part, then setting the CurrentCamera’s CFrame to the part’s CFrame. (Make sure to create this instance on the server as the client can’t detect camera’s other than the CurrentCamera)

I tried to figure out a way using remote events I receive no errors but it also doesn’t print what I want it to print.
image
[Server Script]

local ViewportEvent = game:GetService("ReplicatedFirst").RemoteEvent
local player = game:GetService("Players")

game:GetService("RunService").Heartbeat:Connect(function()
	local viewportCam = script.Parent.Camera
	local data = viewportCam.CFrame
	ViewportEvent:FireAllClients(data)
end)

[Local Script]

local ViewportEvent = game:GetService("ReplicatedFirst").RemoteEvent

game:GetService("RunService").Heartbeat:Connect(function()
	local cam = game:GetService("Workspace").CurrentCamera
	ViewportEvent.OnClientEvent:Connect(function(data)
		print(data)
	end)
end)

It gets the Viewport Camera’s CFrame and puts it into a RemoteEvent fire. The local script should then receive the “data” and print it; however, it doesn’t work.