I can't get the camera to reset after tweening it

Hi, I’m trying to create a system where the camera will tween to one place which i have managed to do, but now i can’t get the camera to reset after finishing. I have tried doing

CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
CurrentCamera.CameraType = "Custom"
CurrentCamera.CFrame = game.Players.LocalPlayer.Character.Head.CFrame

But that has not worked. Although the tween plays to put the camera back to normal, it will just teleport the camera to the position it was just at.

Here is a video of what the issue is.

Plus the the camera script code.


local camPart = workspace.T3.CameraPart
local mouse = game:GetService("Players").LocalPlayer:GetMouse()

local remoteEvent = game.ReplicatedStorage:WaitForChild("T3") 
local Workspace = game:GetService("Workspace")
local CurrentCamera = workspace.CurrentCamera
local TweenService = game:GetService("TweenService")



remoteEvent.OnClientEvent:Connect(function()
	
	
	workspace.T3.Part.ClickDetector.MaxActivationDistance = 0
	
	workspace.T3.Part.Position = workspace.T3.Part.Position + Vector3.new(0,10,0)
	
	CurrentCamera.CameraType = Enum.CameraType.Scriptable
	local TI = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut,0)
	local Goal = {CFrame = Workspace.T3.CameraPart.CFrame}
	TweenService:Create(CurrentCamera, TI,Goal):Play()

	--// Set cam
	repeat
		wait()
		CurrentCamera.CameraType = Enum.CameraType.Scriptable
	until
		CurrentCamera.CameraType == Enum.CameraType.Scriptable
		

	--// Move cam
	local maxTilt = 4
	game:GetService("RunService").RenderStepped:Connect(function()
		CurrentCamera.CFrame = camPart.CFrame * CFrame.Angles(
			math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
			math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
			0
		)
	end)

end)

script.Parent.close.MouseButton1Down:Connect(function()
	
	local TI = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut,0)
	local Goal = {CFrame = game.Players.LocalPlayer.Character.Head.CFrame}
	TweenService:Create(CurrentCamera, TI,Goal):Play()	
	CurrentCamera.CameraType = Enum.CameraType.Custom
	repeat
		wait()
		CurrentCamera.CameraType = Enum.CameraType.Custom
	until
	CurrentCamera.CameraType == Enum.CameraType.Custom
	print("camera changed")
	workspace.T3.Part.Position = workspace.T3.Part.Position - Vector3.new(0,10,0)
	
	CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
	CurrentCamera.CameraType = "Custom"
	CurrentCamera.CFrame = game.Players.LocalPlayer.Character.Head.CFrame
end)

2 Likes

When tweening the camera, make sure it’s set to Scriptable for the entire duration. Your repeat loop can be removed as it is not necessary.
Then set it to Custom only after you are done setting the Cframe back to the player’s head. (also use Head not Humanoid for the subject, I find better results this way, and then I also offset the camera to the back of the head so its not inside the head.)

Hi, yeah im still getting the same result shown in the video,

edited code


local camPart = workspace.T3.CameraPart
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local remoteEvent = game.ReplicatedStorage:WaitForChild("T3") 
local Workspace = game:GetService("Workspace")
local CurrentCamera = workspace.CurrentCamera
local TweenService = game:GetService("TweenService")



remoteEvent.OnClientEvent:Connect(function()
	workspace.T3.Part.Position = workspace.T3.Part.Position + Vector3.new(0,10,0)
	
	CurrentCamera.CameraType = Enum.CameraType.Scriptable
	local TI = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut,0)
	local Goal = {CFrame = Workspace.T3.CameraPart.CFrame}
	
	TweenService:Create(CurrentCamera, TI,Goal):Play()

	wait(2)

	--// Move cam
	local maxTilt = 4
	game:GetService("RunService").RenderStepped:Connect(function()
		CurrentCamera.CFrame = camPart.CFrame * CFrame.Angles(
			math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
			math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
			0
		)
	end)

end)

script.Parent.close.MouseButton1Down:Connect(function()
	
	local TI = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut,0)
	local Goal = {CFrame = game.Players.LocalPlayer.Character.Head.CFrame + Vector3.new(0,2,0)}
	TweenService:Create(CurrentCamera, TI,Goal):Play()
	wait(2)	
	CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Head
	CurrentCamera.CameraType = Enum.CameraType.Custom
	CurrentCamera.CFrame = game.Players.LocalPlayer.Character.Head.CFrame
	
	print("camera changed")
	workspace.T3.Part.Position = workspace.T3.Part.Position - Vector3.new(0,10,0)
	
	
end)

Managed to fix it by replacing the Run service with a while loop

local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local remoteEvent = game.ReplicatedStorage:WaitForChild("Terminal_1") 
local Workspace = game:GetService("Workspace")
local CurrentCamera = workspace.CurrentCamera
local TweenService = game:GetService("TweenService")

local camSet = false


remoteEvent.OnClientEvent:Connect(function()
	workspace.T3.Part.Position = workspace.T3.Part.Position + Vector3.new(0,10,0)
	
	CurrentCamera.CameraType = Enum.CameraType.Scriptable
	local TI = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut,0)
	local Goal = {CFrame = Workspace.T3.CameraPart.CFrame}
	
	TweenService:Create(CurrentCamera, TI,Goal):Play()

	wait(2)
	
	--// Move cam
	local maxTilt = 4
	while camSet == false do
		wait(0.01666666666)
		CurrentCamera.CFrame = camPart.CFrame * CFrame.Angles(
			math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
			math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
			0
		)
	end

end)

script.Parent.close.MouseButton1Down:Connect(function()
	camSet = true
	
	local TI = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut,0)
	local Goal = {CFrame = game.Players.LocalPlayer.Character.Head.CFrame + Vector3.new(-7,2,0)}
	TweenService:Create(CurrentCamera, TI,Goal):Play()
	wait(2)	
	CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Head
	CurrentCamera.CameraType = Enum.CameraType.Follow
	CurrentCamera.CFrame = game.Players.LocalPlayer.Character.Head.CFrame
	
	print("camera changed")
	workspace.T3.Part.Position = workspace.T3.Part.Position - Vector3.new(0,10,0)
	

	
	wait(2)
	script.Parent.Frame.Visible = false
	script.Parent.Circle.Visible = false
	script.Parent.Click.Visible = true
	script.Parent.TextLabel.Visible = true
	script.Parent.TextButton.Visible = true
	
	
end)