I struggled with this problem for a while. I managed to solve it, however, by setting the workspace camera to Camera.CameraType Fixed (it does appear to be working with Custom as well though), and in Starterplayer setting the CameraMode to LockFirstPerson.
This did not work at first, untill I removed all my code that modified UserInputService.MouseBehaviour and player.CameraMode. So removing all the code
that modified it solved my problem.
To be able to move the mouse freely at times, I use a textButton in a ScreenGui with its property Modal set to true.