FirstPerson script locks mouse

When my code runs for my first person script my mouse is locked to the centre of the screen and I can’t move it how can I fix this??

local Plr = game.Players.LocalPlayer
if Plr then
	wait()
	Plr.CameraMode = 0
	Plr.CameraMode = 1
end
script:Destroy()

This is a local script in starterGui

1 Like

You cant move your cursor around the screen while player’s can mode is FirstPerson.

This post should be able to help you - it goes in depth about how to unlock and relock the mouse when in first person.

ok, how would I be able to then??

I will go through the post, but it looks very complex vs to mine.

What are you trying to achieve?

if Plr then
	wait()
	Plr.CameraMode = 0 --Third Person camera mode
	Plr.CameraMode = 1 --First Person camera mode
end

Your script is putting the player into third person and then putting them into first person straight away, that’s why it’s locked.

It seems like your script is intended to set the player’s camera mode to first-person view. However, it’s causing an issue where the mouse is locked to the center of the screen. This could be due to the way the camera mode is being changed. Instead of changing the camera mode twice, you can directly set the CameraMode to 1 to achieve the desired effect. Additionally, you can put this code in a UserInputService.InputBegan event to ensure that the camera mode is set correctly without causing the mouse locking issue.

Here’s an updated version of your script:

luaCopy code

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")

local function setFirstPersonCameraMode()
	local localPlayer = Players.LocalPlayer
	if localPlayer then
		localPlayer.CameraMode = Enum.CameraMode.Classic
	end
end

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if not gameProcessedEvent then
		setFirstPersonCameraMode()
	end
end)

This script listens for input events and then sets the camera mode to first-person view. By using the UserInputService.InputBegan event, you ensure that the camera mode is set when the player interacts with the game and avoid any mouse locking issues that might arise from setting the camera mode twice in a short period.

Place this script in StarterPlayerScripts or StarterCharacterScripts as a LocalScript, depending on where you want the camera mode to be set.

1 Like

put this localscript in starterplayerscripts

local gui = Instance.new("ScreenGui")
local button = Instance.new("TextButton")
button.Transparency = 1
button.Size = Udim2.new(0, 0, 0, 0)
button.Modal = true
button.Parent = gui
gui.Parent = game.Players.LocalPlayer.PlayerGui

is there a way to unlock the mouse as it is stuck in the centre of the screen when in first person. I am try to achieve is having a first person system, but issue is the mouse stops working and won’t move and will stay in the centre of the screen.

this didn’t do anything when i tried it.

try using my script i think that would work

1 Like

I tried this, but it didn’t make me go into first person at all.

Also there were no errors in output.

I’m on my phone today so I won’t be much help.

I’ve been googling your problem and I found a post that might help you:

2 Likes

oh idk if you can do that if you zoom in yourself you also cant move your mouse

1 Like

I noticed that. That is why I was wondering if there was a way to fix that.

i think its a Roblox problem maybe try searching the toolbox for a working script if no one can help you

1 Like

How is this a Roblox problem?

The mouse is force-locked if you’re in first person, this is obviously intentional.

I will try this right now Thanks!!

ive updated my script use that

local gui = Instance.new("ScreenGui")
local button = Instance.new("TextButton")
button.Transparency = 1
button.Size = Udim2.new(0, 0, 0, 0)
button.Modal = true
button.Parent = gui
gui.Parent = game.Players.LocalPlayer.PlayerGui
1 Like

Just be careful of viruses. Look for things like require(), getfenv(), setfenv() or very strange strings that look like: "48/92/72/17/05/59".

1 Like