Disabling player's mouse lock while its enabled ingame

So what I’m trying to do is to forcefully enable and disable a player’s mouselock during the game at any time. Lets say the player loses control of their character temporarily, I don’t want them to rotate the character with shiftmouselock so I disable DevEnableMouseLock. However, if you disable it while the player is in shiftmouse lock, this happens: rD73mim6u9.mp4
The shiftmouse icon disappears, however the mouse continues to be locked. I’ve tried many things such as, changing the userinputservice’s mousebehavior to default, listening for the properties value being changed and then calling


which also did nothing. Searched around devforums for about an hour and can’t seem to find anything that answers my problem. Any ideas?

1 Like

I had answered a question that has a similar answer yesterday. Basically, AFAIK, there’s no way to do this without forking the player control modules as there’s an FFlag that prevents the controller from being returned so we have to remove it via means of using a fork.

Here’s the answer I wrote:

But in short, you take the PlayerModule and remove the FFlag if statement at the end and return the CameraController.

Then, this is the code to toggle it:

local cameras = require(game:GetService('Players').username.PlayerScripts.PlayerModule):GetCameras() 
local mouseLockController = cameras.activeMouseLockController 
mouseLockController.isMouseLocked = not mouseLockController.isMouseLocked -- or you can use true/false

It almost works, only issue is this strange behavior with now moving the camera around. Instead of right clicking and dragging the camera around, it sorta just “clicks”. In this video I’m just clicking and dragging the camera a bunch but it just teleports/clicks P0cIQR8Xm4.mp4 also I appreciate the help, when it comes to messing with roblox’s camera I have no clue.

Ah yeah, I see what you mean. I am not getting that weird click behaviour but instead I’m getting an issue where I can’t right click. I’m gonna have a look and see if I can get it to work as expected, will follow up.

Edit: I ended up stopping play testing then play testing again and it seemed to work as expected. Could you maybe share your modified CameraModule script?

camera repro.rbxl (142.5 KB)
All I do is throw this code in the command bar and then hit shift and wait, disabling DevMouseLock from the player actually has the exact same result.

local cameras = require(game:GetService('Players').LocalPlayer.PlayerScripts.PlayerModule):GetCameras() 
local mouseLockController = cameras.activeMouseLockController 
mouseLockController.isMouseLocked = false
1 Like

Had a look through the scripts again, try this, it should force enable/disable it whenever it’s called but it allows it to be disabled:

local cameras = require(game:GetService('Players').LocalPlayer.PlayerScripts.PlayerModule):GetCameras() 
local mouseLockController = cameras.activeMouseLockController 
mouseLockController.isMouseLocked = not mouseLockController.isMouseLocked 

I had that right click thing happen again but this code worked and disabled/enabled it properly.

I also removed the FFlag if-statement at the top of CameraModule but I’m not sure if that had anything to do with it.

1 Like

Well yeah it does enable/disable it correctly but it still causes that right click bug which is huge so I’m gonna play around with the camerascripts for a while to see if I can find the root to the problem, there’s probably something that isn’t getting ticked properly.

edit: i literally might’ve just found the issue…

in BaseCamera, on line 633 it checks for isMouseLockedMode is true or false to make the mouse behave like shiftmouse or not. Something is causing it to rapidly move back forth.

Found a solution! Kind of hacky but it works really well.

In the video, I’m running some code that just disables and enables DevEnableMouseLock on my player on the server, as you can see my mouse fluently swaps between the two!
All I did was at line 631 inside of the UpdateMouseBehavior function within the BaseCamera script, I added the following:

		if Players.LocalPlayer.DevEnableMouseLock == false then
			self.inMouseLockedMode = false

This works with the default camera code as well so you don’t have to remove any of the FFlags.

1 Like

Could you please provide a file with the scripts inside it? I’m having a hard time following the thread and recreating the effect myself. Thanks!

1 Like