How can I lock the mouse cursor to the middle of the screen?

Hi.
I’m trying to figure out how to lock the mouse cursor to the middle of the client’s screen using UserInputService.MouseBehaviour = Enum.MouseBehaviour.LockCenter but it’s not working and has nothing in output. What can I do here?

13 Likes

Try and set the cursor to {0.5, 0}{0.5, 0} - I don’t know if this will work but it should set it to the centre.

2 Likes

The control scripts are setting MouseBehavior back, so to stop that you will need to set it every frame.

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

The mouse.X and mouse.Y properties are a read-only property, so you can only see them you can’t change them or anything. And as well each property is a number value, not a Udim2 and they are separate so it’s not like mouse.Position

I wish there was a way to control the mouse more.

2 Likes

You can not [directly] control the mouse cursor position. Being able to do so would have some security implications. However, you can create a pseudo-cursor and manipulate that to your liking.

10 Likes

To a solution to this, use a Gui that hides all the screen and set the transparecy of the gui to 1