Shiftlock not working

After unequipping this gun tool, when entering first person or shift-lock, the mouse does not stay centred like it should as seen in the video


This bug only seems to occur when the weapon is aimed into and then unequipped. Aiming in and out of the gun but still keeping it equipped doesn’t produce the bug, it is only after you unequip it the bug occurs. The only code that runs on unequip relating to input at all is:

UserInputService.MouseIconEnabled = true

The aim in function runs these relevant lines of code

Humanoid.AutoRotate = false
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
UserInputService.MouseDeltaSensitivity = ...
workspace.CurrentCamera.CFrame = ...
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter 

The aim out function resets all of these values to their defaults

I can’t see the solution to this bug and it’s really annoying, does anyone know the potential causes of the mouse not staying locked to the centre in shift-lock and first person mode?