Mouse Locking not Working

I’m attempting to lock the mouse to the center of the screen. For some unknown reason, setting the .MouseBehavior of the player’s UserInputService seems to be over-ridden somehow. Code:

--note: this code executes after ample loading time is provided for the player
local UIS = game:GetService('UserInputService')
local RunService = game:GetService('RunService')
RunService:BindToRenderStep('mouseLock',100000,function()
	print(UIS.MouseBehavior)
	UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
	print(UIS.MouseBehavior)
end)

The output alternates between ‘Enum.MouseBehavior.Default’ and ‘Enum.MouseBehavior.LockCenter’. This leads me to believe that UserInputService’s .MouseBehavior is being changed, but something is over-riding the property back to ‘Enum.MouseBehavior.Default’. Any insight OR better practice methods is appreciated!

2 Likes

Simple solution that i can think of, is lock the player in first person

1 Like

Locking the players .CameraMode to be Enum.CameraMode.LockFirstPerson works! Thanks. I also found that setting the .CameraType to Enum.CameraType.Scriptable also works.

1 Like