Code presented in tutorial (DevEnabledMouseLock) cannot run due to security context

Hi! This code here actually doesn’t work in a local script, as the code implied says it does:

local player = game.Players.LocalPlayer
while true do
	player.DevEnableMouseLock = not player.DevEnableMouseLock

Due to security context rules! Please update the docs, preferably with a way to disable mouse locks!


I’ve replaced the code sample on the page. The new code sample shows how a server Script can toggle a player’s ability to use mouse lock. It does this via a chat command “mouselock”.


This change should be visible soon. Hope this is more useful than the existing sample!

1 Like

Thank you!

Wild that this only works on the server. Guess it’s time for an API proposal.

I’m pretty sure that using the PlayerModule you can already toggle mouse lock mode. Unfortunately, the PlayerModule isn’t documented like the Lua Chat System is.

Update, this is possible but due to a fast flag (“UserRemoveTheCameraApi”) you can’t with the stock PlayerModule. You would have to edit the CameraModule script to remove this restriction.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.