Unlock cursor with a keybind in locked first person mode

Question is in the title, please help me. I tried using the GUI technique but it doesn’t work + I want it to be keybind based.

2 Likes
UserInputService.MouseBehavior = Enum.MouseBehavior.None

if I remember correctly, this should work just fine. Alternatively, you can make a Gui Modal.

That’s odd, because the GUI method should work. You also are able to hook it up to a keybind.
I just tried it for myself, and this is what I was capable to come up with:


First thing first, in the StarterGUI folder I added a ScreenGUI, parent of a TextButton, parent of a LocalScript.

image

In the local script I made the following code:

local UIS = game:GetService("UserInputService")

local textButton = script.Parent
local cameraSetting = 0 -- this will be the switch to recognise whether you are
                        -- in a locked cursor or freed cursor state

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then -- set E as any input you wish
		if cameraSetting == 0 then
		textButton.Modal = true
		cameraSetting = 1
	elseif cameraSetting == 1 then
		textButton.Modal = false
		cameraSetting = 0
		end
	else return print("Wrong input") end -- optional to get rid of the print function
end)

p.s. My bad for the deleted post, sent the first one too soon.

2 Likes

Hey thanks, I just found out that I had a custom crosshair script that’s stopping it from working. Thank you!

2 Likes

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