Mouse will not lock

In my r15 game I literally have 1 script running(besides the default one) and all it does it lock the mouse to the center of the screen

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

but it is not working…is there any reason why? I opened a new place and changed it to r15 characters and it worked just fine. It doesn’t work in play solo nor server

Mystic Sands (Pre-Alpha) - Roblox is the place

1 Like

You still have the default Camera scripts in the place right? Those scripts will change the MouseBehavior.

No nothing is in the place at the start, they get put into your player when you start but thats no different than the other places I’ve tested it on and it works just fine

I’m not sure what you mean, if nothing is in the place then you are still using the default PlayerScripts. The CameraScript will control the MouseBehavior, like how right clicking locks the mouse to the current position or zooming to first person locks the mouse to the center of the screen.

I have that script I mentioned above, I go into the place I linked and I paste the script into starter player and the script doesnt work in that place. When I go into any other place, without changing a thing, and paste the script in there it works just fine.

The script doesn’t work.

Try the following:

  1. Create a new empty baseplate game in ROBLOX Studio.
  2. Start play solo.
  3. Run the following code in the command line:
local UserInputService = game:GetService("UserInputService")
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
  1. Observe how your mouse is locked to the center of the screen.
  2. Right click. Observe how your mouse is unlocked by the CameraScript.

The code doesn’t work because when the Camera is initializing it resets the MouseBehavior.
You can see the relevant line of code here:
https://github.com/ROBLOX/Core-Scripts/blob/master/PlayerScripts/PlayerScriptsPlace/StarterPlayer/StarterPlayerScripts/CameraScript/RootCamera.rbxmx#L1140

1 Like

Okay but when I delete the default scripts and run that line it still doesn’t work in the place I linked but it did work in the new blank place and thats why I’m confused.

In the game you linked the camera works, so the default CameraScript is not removed. I see an error in the console from the script PlayerScripts.Camera so maybe that is why it isn’t working. You need to override the default camera script by creating a script called “CameraScript” in StarterPlayerScripts.

Also, read the steps to report a bug, there is nothing in this thread that suggests you are encountering a bug.

I was going to lock the post because we figured out the issue in PMs but maybe someone else will have the same issue.

There was a GuiButton with Modal set to true on-screen, this causes the mouse to be unlocked.
See here: Documentation - Roblox Creator Hub

2 Likes

A post was merged into an existing topic: Off-topic and bump posts

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.