Camera stuttering in CFrame/Camera shift lock switch script

I’ve been making a simple script to read the CFrame rotation of a player’s Camera and apply that to the player’s HumanoidRootPart Rotation.

Here’s the snippets of the scripts - they all work well (in that the ModuleScript where the functions are are actually running, et cetera., so the problem doesn’t lie there but most likely within the reading/writing of the CFrame.)

ModuleScript GunEngineFunctions, where the camera locking function is:

function gunenginefunctions.LockCamera(camera, humanoidrp)
	RunService:BindToRenderStep("mouselock", Enum.RenderPriority.Last.Value + 1, function()
		UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
		UserInputService.MouseIconEnabled = false

	slsconnect = camera.Changed:Connect(function()
		local crotx, croty, crotz = camera.CFrame.Rotation:ToEulerAnglesYXZ()
		local protx, proty, protz = humanoidrp.CFrame:ToEulerAnglesYXZ()
		humanoidrp.CFrame = * CFrame.Angles(protx, croty, protz)

LocalScript GunController, where the tool.Equipped/Unequipped events call the mouse locking functions defined in GunEngineFunctions:

local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")

local gun = script.Parent
local player = gun.Parent.Parent

local mouse = player:GetMouse()

local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local cameratweeninfo =, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)

local ammohud = player:WaitForChild("PlayerGui").AmmoHUDContainer
local crosshair = player.PlayerGui.CrosshairContainer

local gunenginefunctions = require(game.ReplicatedStorage.GunEngineFunctions)

	ammohud.Enabled = true
	crosshair.Enabled = true
	local goal = {}
	goal.CameraOffset =, 1, 0) -- default
	gunenginefunctions.LockCamera(workspace.CurrentCamera, character.HumanoidRootPart)
	TweenService:Create(humanoid, cameratweeninfo, goal):Play()

	ammohud.Enabled = false
	crosshair.Enabled = false
	local goal = {}
	goal.CameraOffset =, 0, 0) -- default
	TweenService:Create(humanoid, cameratweeninfo, goal):Play()

The attached video shows the undesired stuttering effect on the camera. When the player faces forward and moves in that direction, the effect is desirable. However, left/right movement leads to a brief camera shifting effect, and moving backwards leads to a repeated (and extremely quick) camera shifting effect.

Attached video (proof): Stuttering Effect on Vimeo

I’ve searched for solutions relating to this, but haven’t found any that relate to the problem as it is quite specific. I’m hoping that, through the proof I attached, someone is able to find the problem.

Thanks in advance to anyone who gives any useful pointers.