CFrame:Lerp() stutters

I’ve got a menu, where by pressing A or D, the player can choose to customize character, etc… But the problem is, when a player presses A or D for the second time, camera starts to “stutter”. I don’t know any other way to describe the problem

LocalScript
local function tweenCamera(camera, pos)
	print(pos)
	player.Character.cameraValue.Value = pos
	repeat camera.CFrame = camera.CFrame:Lerp(pos.CFrame, 0.5) wait()
	until camera.CFrame == pos.CFrame return
end

local function moveCamera(state)
	print(state)
	local Camera = workspace.CurrentCamera
	local cameraPart = getCamera()
	
	if state == "Right" then
		print(cameraPart)
		local nextCamera = getNextCamera(cameraPart)
		if not nextCamera then
			return print("no previus camera")
		end
		
		tweenCamera(Camera, nextCamera)
	elseif state == "Left" then
		print(cameraPart)
		local prevCamera = getPreviousCamera(cameraPart)
		if not prevCamera then
			return print("no previus camera")
		end
		
		tweenCamera(Camera, prevCamera)
	end
end

Here’s the video (I am pressing A and D on the video)

Why not just use actual tween service?

local ts = Game:GetService("TweenService")
local function tweenCamera(camera, pos)
   ts:Create(camera, TweenInfo.new(1), {CFrame = pos.CFrame}):Play()
end
1 Like