LockCenter and LockCurrentPosition are Broken

Issue Type: Other
Impact: High
Frequency: Constantly
Date First Experienced: 2020-03-25 00:03:00 (+00:00)
Date Last Experienced: 2021-02-17 00:02:00 (+00:00)

Reproduction Steps:

  • Create LocalScript in PlayerStarterScripts

  • Insert the following lines of code

    local UserInputService = game:GetService("UserInputService")
    UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter

  • Hit Play

Expected Behavior:
When mouse behaviour is locked, the mouse is meant to be locked either to the center of the screen or its last position.

Actual Behavior:
The mouse is free to move around the screen.

Workaround:
This is a fixed player module rbxm.
Apparently lines 1129 through to 1134 in the BaseCamera module set MouseBehavior to default every frame.

PlayerModule-Fixed.rbxm (110.0 KB)

Duplicate of old bug from March last year:

11 Likes

Correction this works when binding it to RenderStep and a priority higher than the Camera priority. But I don’t believe this behaviour is documented anywhere.

local UserInputService = game:GetService("UserInputService")

game:GetService("RunService"):BindToRenderStep("MouseLock", Enum.RenderPriority.Camera.Value + 1, function()
	UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
end)
5 Likes

Thanks for the report! We’ve filed a ticket to our internal database and we’ll follow up when we have an update for you.

5 Likes

Thanks for the follow-up on this Opplo.
I manged to get around this by modifying something in one of the local player scripts. I can’t remember what exactly I changed but it solved the problem for me. I just had to make sure that the fixed duplicate was in the starter player folder.

Elliot

I can confirm this is still happening as of May 2021.

There is a workaround, but it’s still an undesired bug as I wasn’t sure if it was my code or another problem with Roblox.

The culprit is line 1384 in the camera script PlayerModule.CameraModule.BaseCamera as shown below. By commenting it out, I no longer have the issue. It does appear for me like it’s reverting it every frame which would render UserInputService.MouseBehavior useless unless if you use a RunService loop as pointed out by @opplo.

8 Likes

Bug is still alive and kicking.

I tried to override the PlayerModule code to see if it would stop resetting the MouseBehavior to default, but the issue still persists. May this be something internal?

4 Likes

Can confirm that this bug has been unresolved to this day - developers still have to resort to using workarounds that don’t always work right out of the box:

In the first clip, rotation was successful using UserInputService:GetMouseDelta() and having the MouseBehavior changed to Enum.MouseBehavior.LockCurrentPosition (Also tested LockCenter with the same results). Note that the line of code used to change the behavior property was within a RenderStepped loop.

In the second clip below , the code used was the exact same - only the line of code changing MouseBehavior was one line before the RenderStepped loop was created. (Therefore being set only once. To provide context: The RenderStepped loop ends when the user stops holding their Left Mouse button. Setting the Mouse behavior only happens once in my moudule script with no other code that could ever possibly conflict with it.) As you can see, the property is never actually set or is instantly overridden by an internal script or the Roblox engine.

2 Likes

Bump. Still seems unresolved.

Making do with hacky workarounds but it’d be nice to have this fixed.

1 Like

currently dealing with this ugh

Thanks for reporting this! We’re currently looking into it! Will keep you updated once it’s been fixed.

At the mean time, the bug is happening only if the window gets re-focused. So if you change the MouseBehavior when UserInputService.WindowFocused, for example:

local UserInputService = game:GetService("UserInputService")

UserInputService.WindowFocused:Connect(function()
	UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
end)

This should set the MouseBehavior with correct behavior. Hope it helps!

3 Likes

Sorry for the long waiting. This should be resolved now.

I’m still having this issue. On a new place, it resets when it is set to LockCenter but not when set to LockCurrentPosition.

I can vouch, I have the exact same issue as @ThePyooterMallard

-- Variables and Services
local States = game.Players.LocalPlayer.PlayerScripts:WaitForChild("StateMachines")
local WeaponEquippedState = States.WeaponEquipped
local InputService = game:GetService("UserInputService")

-- Upon Value Changed, Switch Mouse Behavior
WeaponEquippedState.Changed:Connect(function()
	
	-- Check Value then switch states
	if WeaponEquippedState.Value == true then
		
		InputService.MouseBehavior = Enum.MouseBehavior.LockCenter
		
	else
		
		InputService.MouseBehavior = Enum.MouseBehavior.Default
		
	end
	
end)

Does not work unless I have it in a Renderstepped