Save the original position of a camera before tween

Hello!

Currently, I’m working on a script that tweens the player’s camera. It will activate from wherever the player’s camera currently is. However, I’m wondering if there is a way to save where the player’s camera WAS and revert the player’s camera back to where it was.

I could, of course, make it so the camera goes back to where it was using the tween, but the camera only activates when an event occurs. I also want the camera to reverse when an event occurs, which is why I want to try to save the current camera position.

Is it possible to save the current position of the camera?

1 Like

Make a variable to store the camera’s CFrame in before you tween.

1 Like

It would be something like
local positionBeforeTween = game.Workspace.CurrentCamera.CFrame
before you tween it.

This sadly does not work; I tested it in studio and when I went to reverse the camera, it went to 0,0,0.

This errors my script.

What appears in the output:
bad argument #1 (Vector3 expected, got CFrame)

Yeah sorry, my bad. Do
local positionBeforeTween = game.Workspace.CurrentCamera.CFrame.Position
Thats for the position. If you want the cframe after then you would do CFrame.new(positionBeforeTween)

It doesn’t error, thankfully; however, it still moves the camera to 0, 0, 0.
I wrote a line to print out what the variable positionBeforeTween is. Here what it says:

0, 7.80868769, 9.76085949, 1, 0, 0, 0, 1, 0, 0, 0, 1

My guess is that the first three numbers are for the camera position and the last six are for orientation. I still don’t understand why it’s going to 0, 0, 0, though. Strange.

I found an article with the same issue:

@H_mzah gave a pretty good explanation of it and even included a rbxl file.

Use local oldCFrame = CAMERA.CFrame before tweening it, then use CAMERA.CFrame = oldCFrame to revert it back to its original position and orientation.