MouseBehavior.Classic does not make the mouse move freely

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)
2 Likes

You need to put it in a runservice event. It’s kinda stupid imo

1 Like

I don’t know how i could implement that into my code as the player presses a Key to unlock the mouse

1 Like
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)

my bad the edited code looks kinda garbage

1 Like

it’s like that because i was rushing to make that, i figured out a way tough

1 Like

Sorry, I didn’t mean it like that. I meant to say that the way I edited it looks bad.

1 Like

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