How to get Players Current Camera Position?

Hey, looking to get the player camera position.

For example, I have a gun which you can scope in, but it’s third person.
Currently, I’m using CameraMode.LockFirstPerson to go first person.
However, whenever I take it off it wouldn’t return to the original position.

Thank you in advanced!

1 Like

You could have taken a look at the properties of Camera object -
Camera Object

Camera Object has a CFrame property which holds the position and the orientation.

1 Like

You can get a player’s current camera position by the CFrame’s position. What I mean by that is; camera.CFrame.p

The p basically is the position!

Edit: You can only achieve this through a LocalScript!

1 Like

I see thank ya, how would I now assign this position to set the players camera to it?
When i try it just says “Position cannot be assigned to”

Can you elaborate more? Like the player’s camera is already in that position. Do you want like a part to be set to the player’s camera position or something?

Basically, I grab the players old camera position, and then their camera position gets moved into a new position for something.

After that something, I want it to return back to their old position

Hopefully that helps a bit !

You can’t set CurrentCamera.CFrame.p directly. You’d have to save the old player’s camera CFrame and then set it back when you need to.

local cframeBefore = workspace.CurrentCamera.CFrame

-- your code happens
-- reverting it back to the old cframe:
workspace.CurrentCamera.CFrame = cframeBefore

I’m a bit rusty on camera-related programming, so you might have to switch the CurrentCamera.CameraType to Enum.CameraType.Scriptable.

1 Like

I don’t really think position will work out for this one. You need to use CFrames’.

So, first of all you need to store their old camera CFrame in a variable. Like this:

local Camera = workspace.CurrentCamera
local OldCamCF = Camera.CFrame -- This variable stores the old camera CFrame!

Then lets say, you want to change it back after 10 seconds, so we’ll do

local Camera = workspace.CurrentCamera
local OldCamCF = Camera.CFrame -- This variable stores the old camera CFrame!

task.wait(10)

Camera.CFrame = OldCamCF

However, you do need to set the camera’s CameraType to scriptable.

So,

local Camera = workspace.CurrentCamera -- The camera

repeat
    task.wait(0.2)
    Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
-- Repeating to set the Camera's CameraType to Scriptable every 0.2 seconds until it's set to Scriptable!

So, our full script will be:

local Camera = workspace.CurrentCamera -- The camera

repeat
    task.wait(0.2)
    Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
-- Repeating to set the Camera's CameraType to Scriptable every 0.2 seconds until it's set to Scriptable!

local OldCamCF = Camera.CFrame -- This variable stores the old camera CFrame!

task.wait(10) -- Waits 10 seconds!

Camera.CFrame = OldCamCF -- Sets the camera CFrame to the CFrame we stored in the variable!

I gotcha thanks, how would I include the Players Zoom Distance as well in that?

Nevermind I got that down, alright thank ya that’s all here !

( + Thank you @everyone who replied too )

1 Like

You can try lowering down the FOV (FieldOfView)!