I have a script to make the player only look left and right by changing the position of the humanoid to the camera's left and right vector. The problem with my script is that it changes the character from left to right instantly, which looks off. Is there a way I can slow it down, or smooth it? Here's my script

local keyA = false
local keyD = false

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.D then
		keyD = true
	elseif inputObject.KeyCode == Enum.KeyCode.A then
		keyA = true
	end
end)

game:GetService("UserInputService").InputEnded:connect(function(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.D then
		 keyD = false
	elseif inputObject.KeyCode == Enum.KeyCode.A then
		 keyA = false
	end
end)

spawn(function()
	while true do wait ()
		if keyA == true and keyD == false then
			root.CFrame = CFrame.new(root.Position, root.Position - camera.CFrame.RightVector)
		elseif keyA == false and keyD == true then
			root.CFrame = CFrame.new(root.Position, root.Position + camera.CFrame.RightVector)
		end
	end
end)