MouseBehaviour.LockCenter is not working

I want to set lock the mouse in the center of the screen, but everything I have tried (Including prioritized HeartBeat) does not work. I even created a blank baseplate just to make sure there’s nothing wrong internally with my project, and the issue still persists.

As far as I’m concern, this might be attributed to the default roblox camera script, which is overlapping my properties.

Here’s my code in a local script in the StarterCharacterScripts:

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

game:GetService("RunService"):BindToRenderStep("mouseLoop", Enum.RenderPriority.Camera.Value + 1, function(dt)
	UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter 
	print(UserInputService.MouseBehavior)
end)

It will print out Enum.MouseBehavior.Default immediately. But one thing I noticed is that the camera does not rotate significantly when holding the left mouse button.

Is there any way for me to fix this issue ? Thanks.

2 Likes

Looks a lot like a bug to me. Roblox recently is having some input issues, on the UWP app any macros and autoclickers work but for me the other apps like the desktop app and studio do not work with macros.

1 Like

I second this, the issue I had was only present in Studio, not when I play test in the Roblox web app itself.

1 Like

You shouldn’t attempt to make a change over & over again in a loop as you will find that it will exhaust the ROBLOX default camera system & mouse. Especially with MouseBehaviour.

Do something like this instead:

local runService = game:GetService("RunService")
local userInput = game:GetService("UserInputService")

runService.RenderStepped:Connect(function(deltaTime)
    if userInput.MouseBehaviour ~= Enum.MouseBehaviour.LockCenter then
        userInput.MouseBehaviour = Enum.MouseBehaviour.LockCenter
    end
end)


Note: I haven’t tested this code, but it still shows the general premise of what I’m trying to advise. Make sure you’re not changing the MouseBehaviour when it doesn’t need to be otherwise you’ll over-exhaust the system into melting down.

your code should work but i think they want to bind it

-- //services
local runservice = game:GetService("RunService")
local userinputservice = game:GetService("UserInputService")

-- //player
local player = game.Players.LocalPlayer

function mouseLoop()
	
	userinputservice.MouseBehavior = Enum.MouseBehavior.LockCenter
	
end

if userinputservice.MouseBehavior ~= Enum.MouseBehavior.LockCenter then
	print(userinputservice.MouseBehavior)
	runservice:BindToRenderStep("mouseString", 1, mouseLoop)
else
	runservice:UnbindFromRenderStep("mouseString")
	print(userinputservice.MouseBehavior)
end
1 Like

Yeah if they need to create binds, I was just pointing out as earlier this week I encountered a problem with ROBLOX where if you have a loop or binded RunService function constantly changing Mouse Properties you will be unable to rotate the camera with the mouse like usual using the default ROBLOX camera system.

1 Like

i think roblox itself is broken - some of my pathfinding code doesnt even compute with the path at all, i get “No Path” when there is a clear path. Might js be me.

but you should report that to roblox bugs they might fix it