How to make player lock first person?

Hi, I have a camera script which uses Enum.CameraType.Scriptable. I tried setting the camera mode to LockFirstPerson with script and StarterPlayer, but it wont work. Anyway to recreate camera mode with Scriptable? Or changing the camera settings with the ability to set cframe with locking?

Here is the code by the way:
local Camera = workspace.CurrentCamera
local Player = game.Workspace.Player
local Mouse = game.Players.LocalPlayer:GetMouse()
local Sensitivity = 16.5

local OldMousePosition = {Mouse.X,Mouse.Y}
Mouse.Move:Connect(function()
	Player.Camera.Orientation += Vector3.new((Mouse.Y-OldMousePosition[2])*-1.6,(Mouse.X-OldMousePosition[1])*-1,0)/Sensitivity
	OldMousePosition = {Mouse.X,Mouse.Y}
end)

while wait() do
	Camera.CFrame = Player.Camera.CFrame
	Camera.CameraType = Enum.CameraType.Scriptable
end

The script is in StarterGui if that matters.

Thanks

1 Like

I tried to find something on google and devforum, but I couldn’t find anything.

Do you mean shift lock or just first person gameplay?

First person gameplay. I am trying to make my own camera script, not using the roblox one. But I want to get rid of the roblox cursor and stop it from going offscreen. Anyway to make it stay in the middle or not go offscreen?

In StarterGui you could add a local script
Code:
local Plr = game.Players.LocalPlayer
Plr.CameraMode = Enum.CameraMode.LockFirstPerson

1 Like

It doesn’t work, I am using Camera.CameraType = Enum.CameraType.Scriptable. It doesn’t allow lock first person.

Alright then. I found this on the Developer Hub. It might be useful. It has a custom camerascript.
https://developer.roblox.com/en-us/api-reference/property/UserInputService/MouseBehavior?msclkid=bbe5823bcf3b11ec9ba6f575a579070a

1 Like

i mean only a script on anywhere

local MaxZoomDistance = 0

game.StarterPlayer.CameraMaxZoomDistance = MaxZoomDistance
1 Like

The locking part worked! But the move.Move doesn’t function anymore. Is there a way I could fix it?

CameraType is used for setting the camera to fixed, scriptable, or custom. CameraMode is setting it to LockFirstPerson. You were trying to use CameraType to do CameraModes job.

local player = game.Players.LocalPlayer

player.CameraMode = Enum.CameraMode.LockFirstPerson

This is all I used in the script and it worked perfectly, as for why the move.move doesn’t work I am not entirely sure. Also, when locking first person, make sure to set it from the player and not the camera. The camera can’t lock first person, but from the player, it can.

I could be entirely wrong, but from what I gather, this is what happened.

1 Like

Yeah the problem was that when using a Scriptable camera the player can still move there mouse normally. CameraMode serves no function on Scriptable camera types.

The mouse behaviour and Input.Delta was what I was looking for. Thanks.

Even after the problem is solved, I have 1 question. What exactly is the “Player” Variable?(game.Workspace.Player)