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.
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?
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.
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!