MouseBehavior = Enum.MouseBehavior.LockCenter Does nothing

This is literally the only script in the entire game and it’s doing nothing

local UserInputService = game:GetService("UserInputService")

while wait() do
	UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
end

Create a new place and put it in a local script anywhere…

Note that out of me being desperate I put it inside a while loop when it shouldn’t need to anyway. I should just set it once and it should stay that way. printing UserInputService.MouseBehavior literally right under where I set it returns Default

It works perfectly fine for me; is there anything in output?

Try using runservices loops to lock it to lockcenter. (Also try avoid using while wait() do loops because it can cause lag even if it’s not an expensive function.)

You have that a little backwards. Wait doesn’t cause lag, it is susceptible to lag and there is nothing especially wrong with it if you need large delays where a few miliseconds of imprecision is acceptable.
Putting this in a RunService event would actually cause more lag since it would run more frequently.
It shouldn’t be necessary to have it in a loop either way.

OP, I suggest ditching the loop and putting it in StarterCharacterScripts.

4 Likes

Wait functions would cause wait() delays and lag if there are more wait functions in the game iirc, Runservice runs loops faster than using while wait() do, but there will still be lag to these loops if it’s running an expensive function so running it frequently doesn’t mean it would lag if I want to at least change the mousebehavior to lockcenter.

It’s advisable to avoid while wait() do and replace to using runservice loops because it doesn’t also run exactly in every frame.

That’s how I have it already. Nothing works…

I still need help…

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

This issue is actually a long-standing engine bug that is beyond absolute developer control - I have recently been experiencing this issue myself when trying to change the MouseBehavior type to LockCurrentPosition (Same goes with LockCenter) but it appears that setting the property within a RenderStepped/Heartbeat/Stepped loop provides mostly variable success:

2 Likes