How to return the original position of the camera if it was moved with TweenService?

Well, my problem is that when I move the camera with tweenService and return it, it returns directly to the head position and not to the original position that the camera had and I really don’t know how to fix it. When it “returns” the position is on line 24 to 28

local Workspace = game:GetService("Workspace")
local TweenService = game:GetService("TweenService")

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character

local CurrentCamera = Workspace.CurrentCamera

local isOpen = false

script.Parent.MouseButton1Down:Connect(function()
	isOpen = not isOpen
	if isOpen then
		CurrentCamera.CameraType = Enum.CameraType.Scriptable
		local tweenInfo = TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0)
		local CameraStartPart = {CFrame = Workspace:WaitForChild("CameraStart").CFrame}
		local CameraTweenStart = TweenService:Create(CurrentCamera, tweenInfo, CameraStartPart)
		CameraTweenStart:Play()
		script.Parent.Text = "Abierto"
	else
		CurrentCamera.CameraType = Enum.CameraType.Scriptable
		local tweenInfo = TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0)
		local CameraStartPart = {CFrame = Character:WaitForChild("Head").CFrame}
		local CameraTweenStart = TweenService:Create(CurrentCamera, tweenInfo, CameraStartPart)
		CameraTweenStart:Play()
		CameraTweenStart.Completed:Wait()
		CurrentCamera.CameraType = Enum.CameraType.Custom
		script.Parent.Text = "Cerrado"
	end
end)
1 Like

Save camera CFrame as variable before tweening it

Yes but how do I do it?, I don’t even know where to get the original CFrame from the camera

Pretty sure it’s
local firstCFrame = Camera.CFrame
Other way you can change camera subjectobject to players humanoid

okey, now I put it in an IntValue or some compatible value, right?

No? Just do it in script, there is no need to make instances

Yes, I already have an idea but it gave me an error “Unable to cast to Dictionary” In the part of:
local CameraTweenStart = TweenService:Create(CurrentCamera, tweenInfo, CamCFrameFInish)

The part that connects the two is:

local CurrentCamera = Workspace.CurrentCamera
local CamCFrameFInish = CurrentCamera.CFrame


local CameraTweenStart = TweenService:Create(CurrentCamera, tweenInfo, CamCFrameFInish)

I’ve answered a problem like this here is the link. It might work.Here
Btw I just looked at the title and wrote this, I might be wrong.

Yes but anyway thanks, it was with the TweenService

I already solved this but now it does not move to the original position but it goes elsewhere

local Workspace = game:GetService("Workspace")
local TweenService = game:GetService("TweenService")

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character

local CurrentCamera = Workspace.CurrentCamera

local CamCFrameFInish = {CFrame = CurrentCamera.CFrame}

local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0)

local isOpen = false

script.Parent.MouseButton1Down:Connect(function()
	isOpen = not isOpen
	if isOpen then
		CurrentCamera.CameraType = Enum.CameraType.Scriptable
		local CameraStartPart = {CFrame = Workspace:WaitForChild("CameraStart").CFrame}
		local CameraTweenStart = TweenService:Create(CurrentCamera, tweenInfo, CameraStartPart)
		CameraTweenStart:Play()
		script.Parent.Text = "Abierto"
	else
		CurrentCamera.CameraType = Enum.CameraType.Scriptable
		local CameraTweenStart = TweenService:Create(CurrentCamera, tweenInfo, CamCFrameFInish)
		CameraTweenStart:Play()
		CameraTweenStart.Completed:Wait()
		CurrentCamera.CameraType = Enum.CameraType.Custom
		script.Parent.Text = "Cerrado"
	end
end)

I changed it up so after the tweening of the camera it goes back to the player. This is the script:
local Workspace = game:GetService(“Workspace”)
local TweenService = game:GetService(“TweenService”)

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character

local CurrentCamera = Workspace.CurrentCamera

local CamCFrameFInish = {CFrame = CurrentCamera.CFrame}

local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0)

local isOpen = false

script.Parent.MouseButton1Down:Connect(function()
	isOpen = not isOpen
	if isOpen then
		CurrentCamera.CameraType = Enum.CameraType.Scriptable
		local CameraStartPart = {CFrame = Workspace:WaitForChild("CameraStart").CFrame}
		local CameraTweenStart = TweenService:Create(CurrentCamera, tweenInfo, CameraStartPart)
		CameraTweenStart:Play()
		script.Parent.Text = "Abierto"
	else
		CurrentCamera.CameraType = Enum.CameraType.Scriptable
		local CameraTweenStart = TweenService:Create(CurrentCamera, tweenInfo, CamCFrameFInish)
		CameraTweenStart:Play()
		CameraTweenStart.Completed:Wait()
		CurrentCamera.CameraType = Enum.CameraType.Custom
		CurrentCamera.CameraSubject = Character.Humanoid

		CurrentCamera.CameraType = "Custom"

		CurrentCamera.CFrame = Character.Head.CFrame
		script.Parent.Text = "Cerrado"
	end
end)

Now it should be able to work. I tested it out.

1 Like

It doesn’t work but I already have the solution, thanks

I tested it and it worked. That’s weird.