Mouse lock center script doesnt work

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    i want to make mouse lock in the center when player join the game

  2. What is the issue? Include screenshots / videos if possible!
    i tried to use the simple script and it doesnt work:

game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i tried while do and its work but i cant change it to default
while wait() do
	game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
end

this is the script i tried.

any solutions would be helpful to me
Thank You.

You cannot lock the mouse without forking the control module. If you want the mouse in the center, you don’t need to repeat it but just wait 2 seconds.

1 Like

You can simply use .CharacterAdded and then check for player.Character with “if” so that the default controls don’t override the code when the player spawns.

game:GetService("Players").LocalPlayer.CharacterAdded:Connect(function()
	if game:GetService("Players").LocalPlayer.Character then
		game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
	end
end)
1 Like

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