A little help with recoil recovery

Currently I am working on a recoil script for my weapons. But I am struggling with recoil recovery (where the camera returns to the position before the gun was fired)

This is what I have tried:

cam = game.Workspace.CurrentCamera
targetCFrame = cam.CoordinateFrame * CFrame.Angles( math.rad(1), math.rad(0), math.rad(0)) * 
CFrame.new(0,0,0)
local ready = true
local function recoil()

    cam.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
    cam.CameraType = "Custom"
    local endCFrame = game.Players.LocalPlayer.Character.Head.CFrame

    if script.Parent.Handle.Fire.Played then
	    yRandom = math.random(2,6)
	    xRandom = math.random(-2,2)
	    zRandom = math.random(-2,2)
	    targetCFrame = cam.CoordinateFrame * CFrame.Angles( math.rad(yRandom), math.rad(xRandom), math.rad(zRandom)) * CFrame.new(0,0,0)
	    cam.CoordinateFrame = cam.CoordinateFrame:Lerp(targetCFrame, 0.7)
    end
    wait(0.1)

    for i = 0,1,1/60 do
	    cam.CFrame = cam.CFrame:Lerp(endCFrame, i) -- rec recovery
	    wait(1/60)
    end
end