I am trying to make so that when ever the player presses the N key it unlocks the mouse by using UserInputService.MouseBehavior as it’s LockToFirstPerson
The problem is that when N is pressed nothing happens
I’ve tryed to set the Number value instead of Enum.MouseBehavior and it still did not work
Here’s the code:
local uis = game:GetService("UserInputService")
local mouseFree = false
uis.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
if input.KeyCode == Enum.KeyCode.N and gameProcessedEvent == false then
if mouseFree then
uis.MouseBehavior = 1
mouseFree = false
elseif not mouseFree then
uis.MouseBehavior = 0
mouseFree = true
end
end
end)
local uis = game:GetService("UserInputService")
local mouseFree = false
uis.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
if input.KeyCode == Enum.KeyCode.N and gameProcessedEvent == false then
if mouseFree then
game:GetService("RunService").Heartbeat:Connect(function(dt)
uis.MouseBehavior = 1
end)
mouseFree = false
elseif not mouseFree then
game:GetService("RunService").Heartbeat:Connect(function(dt)
uis.MouseBehavior = 0
end)
mouseFree = true
end
end
end)