Shift Lock & GUI

Simple question. How do you make it so that if a player is using shift lock, when a gui pops up, they can move their mouse, but when the gui is closed, the mouse gets put in the middle until shiftlock is toggled off?

2 Likes

You can’t control the client’s mouse but you can force the player into first person until they press the shift key.

1 Like
local userInput = game:GetService("UserInputService")
local players = game:GetService("Players")
local player = players.LocalPlayer

local toggle = false

userInput.InputBegan:Connect(function(input, processed)
	if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.RightShift then
		toggle = not toggle
		player.CameraMode = if toggle then Enum.CameraMode.LockFirstPerson else Enum.CameraMode.Classic
	end
end)

Here’s an example script which toggles the player between first person camera & classic camera mode when either shift key is pressed.

1 Like

That’s not the problem. I just want it so that if the player is currently using shiftlock, they can still move around their mouse on GUIs.

This is documented. Shift lock sets the MouseBehavior to LockCenter. GuiButtons with Modal on will override this. If you have any buttons on your interface set their Modal property to true. If your interface has no buttons, you can hack around this by making an offscreen button with Modal on.

Note that the GuiButton needs to be within the screen’s bounds and visible.

3 Likes

Thanks, I put a tiny button in the middle of the screen, and it unlocks the mouse while the gui is open.

Thanks!