Sway Effect not applying to Viewmodel

So I recentlty started working on a Viewmodel and wanted to add Sway Effect

The problem is I don’t have any errors and the Sway Effect is not applying to the model

Code :

coroutine.wrap(function()
	RunService:BindToRenderStep("CameraRender", Enum.RenderPriority.Camera.Value + 1, function()
		local lastCFrame = camera.CFrame
		local Orientation = camera.CFrame:ToObjectSpace(lastCFrame)
		local x, y, z = Orientation:ToOrientation()

		SwayCFrame = SwayCFrame:Lerp(CFrame.new(math.sin(x)*6, math.sin(y)*6, 0), 0.1)

		lastCFrame = camera.CFrame
	end)
end)()



RunService.RenderStepped:Connect(function(deltaTime)
	if WeaponViewmodel then
		WeaponViewmodel:SetPrimaryPartCFrame(
			camera.CFrame *
				MainCFrame *
				SwayCFrame *
				BobbleCFrame *
				AimingCFrame
		)
		
		
		if Aiming then
			AimingCFrame = AimingCFrame:Lerp(WeaponData.AimingCFrame, .5)
		else
			AimingCFrame = AimingCFrame:Lerp(CFrame.new(), .5)
		end
	end
end)

Thanks for help !

Ok, Figured out, when doing this method : Set ‘lastCameraCFrame’ at CFrame.new(0, 0, 0) at the start of your local script

Code :

local lastCameraCF = CFrame.new()
-- other variables
RunService.RenderStepped:Connect(function(deltaTime)
	local rotation = workspace.CurrentCamera.CFrame:toObjectSpace(lastCameraCF) 
	local x,y,z = rotation:ToOrientation() 
	SwayCFrame = SwayCFrame:Lerp(CFrame.Angles(math.sin(x)*SwayMultipler,math.sin(y)*SwayMultipler,0), 0.1)	
	lastCameraCF = workspace.CurrentCamera.CFrame
-- rest of code