Camera not working due to OTS script

So I have this error in game. This is the script before and a video…

local Camera = {}
local Meta = {__index = Camera}
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInput = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local OriginalSense = UserInput.MouseDeltaSensitivity
local currentCamera = workspace.CurrentCamera
local Utilities = script:FindFirstAncestorWhichIsA("Folder")
local RecSpring = require(Utilities:WaitForChild("RecoilSpring"))

local PlayerGui = Players.LocalPlayer:WaitForChild("PlayerGui")
local ScreenDistortions = PlayerGui:WaitForChild("Distortions")

local MinTransparency = .25
local LeftShoulderPos = Vector3.new(3.5, 0, 6)
local RightShoulderPos = Vector3.new(-3.5, 0, 6)
UserInput.MouseIconEnabled = true

local Camerabind = "OTSCamera"
local Enabled = true
local Binded = {}
local Connections = {}
local Infos = {
	SwapShoulder = TweenInfo.new(
		.5,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	);
	AimLerp = TweenInfo.new(
		.4,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	);
	RootLerp = TweenInfo.new(
		.1,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	);
}

-- Localized Globals
local ray = Ray
local CF = CFrame
local V3 = Vector3
local rad = math.rad
local clamp = math.clamp

local DistortIn = TweenService:Create(ScreenDistortions.CleanDistort, Infos.AimLerp, {ImageTransparency = .3})
local DistortOut = TweenService:Create(ScreenDistortions.CleanDistort, Infos.AimLerp, {ImageTransparency = 1})

local function Initilization(self)
	if Binded[Camerabind] then return end
	currentCamera.CameraType = Enum.CameraType.Scriptable
	UserInput.MouseIconEnabled = true
	BindToRenderStep(Camerabind, Enum.RenderPriority.Camera.Value, function(delta)
		UserInput.MouseBehavior = Enum.MouseBehavior.LockCenter
		self:Update(delta)
	end)
	table.insert(Connections, UserInput.InputChanged:Connect(function(input)
		trackInput(input, self)
	end))
	table.insert(Connections, self.Humanoid.Died:Connect(function()
		self:SetEnabled(false)
	end))
end

function BindToRenderStep(key, priority, func)
	Binded[key] = func

	RunService:BindToRenderStep(key, priority, func)
end

function UnbindFromRenderStep(key, self)
	RunService:UnbindFromRenderStep(key)
	if Binded[key] then
		Binded[key] = nil
	end
	for _, Connection in pairs(Connections) do
		Connection:Disconnect()
	end
	Connections = {}
	self.Humanoid.AutoRotate = true
	self.Aiming = false
	DistortOut:Play()
	currentCamera.CameraType = Enum.CameraType.Custom
	UserInput.MouseBehavior = Enum.MouseBehavior.LockCenter
	UserInput.MouseDeltaSensitivity = OriginalSense
	UserInput.MouseIconEnabled = true
end

function trackInput(input, self)
	if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
		self.XAngle = self.XAngle - input.Delta.X * .4
		self.YAngle = clamp(self.YAngle - input.Delta.Y * .4, -80, 80)
	end
end

function Camera.new(Character)
	local self = {}

	self.Character = Character
	self.SubjectRoot = Character.HumanoidRootPart
	self.Head = Character.Head
	self.Humanoid = self.Character:FindFirstChildOfClass("Humanoid")
	self.IsAlive = self.Humanoid:GetState() ~= Enum.HumanoidStateType.Dead

	self.XAngle = 0
	self.YAngle = 0
	self.Recoil = RecSpring.new(Vector3.new(), Vector3.new(), Vector3.new(), 20, 1)
	self.CameraOffset = script:WaitForChild('DefaultCameraPos') -- default location
	self.BaseFOV = currentCamera.FieldOfView
	self.Aiming = false

	self.Shoulder = "Left"
	self.RightTween = TweenService:Create(self.CameraOffset, Infos.SwapShoulder, {Value = RightShoulderPos})
	self.LeftTween = TweenService:Create(self.CameraOffset, Infos.SwapShoulder, {Value = LeftShoulderPos})

	Initilization(self) -- default behavior when u first call .new()
	return setmetatable(self, Meta)
end

function canOcclude(part)
	return part.Transparency < MinTransparency and part.CanCollide and not part:IsA("TrussPart")
end

function Camera:SetEnabled(boolean)
	if boolean ~= Enabled then
		Enabled = boolean
	end
	if Enabled == false and Binded[Camerabind] then
		UnbindFromRenderStep(Camerabind, self)
	elseif Enabled == true and not Binded[Camerabind] then
		Initilization(self)
	end
end

function Camera:UpdateADS(boolean, value)
	if self.Aiming ~= boolean then
		self.Aiming = boolean
	end
	if boolean == true then
		self.Humanoid.AutoRotate = false
		UserInput.MouseIconEnabled = true
		UserInput.MouseDeltaSensitivity = UserInput.MouseDeltaSensitivity/2.8
		TweenService:Create(currentCamera, Infos.AimLerp, {FieldOfView = value}):Play()
		DistortIn:Play()
	elseif boolean == false then
		self.Humanoid.AutoRotate = true
		UserInput.MouseIconEnabled = true
		UserInput.MouseDeltaSensitivity = OriginalSense
		TweenService:Create(currentCamera, Infos.AimLerp, {FieldOfView = self.BaseFOV}):Play()
		DistortOut:Play()
	end
end

function Camera:SwapShoulders(side)
	if self.Shoulder == "Right" and side == "Left" then
		self.LeftTween:Play()
	elseif self.Shoulder == "Left" and side == "Right" then
		self.RightTween:Play()
	end
	self.Shoulder = side
end

function Camera:Update(delta)
	if not self.IsAlive then self:SetEnabled(false) return end
	local CameraOffset = self.CameraOffset.Value
	local StartCFrame = CF.new((self.SubjectRoot.CFrame.Position + V3.new(0, 2, 0))) * CF.Angles(0, rad(self.XAngle), 0) * CF.Angles(rad(self.YAngle), 0, 0)

	local CameraCFrame = StartCFrame + StartCFrame:VectorToWorldSpace(V3.new(CameraOffset.X, CameraOffset.Y, CameraOffset.Z))
	local CameraFocus = StartCFrame + StartCFrame:VectorToWorldSpace(V3.new(CameraOffset.X, CameraOffset.Y, -50000))
	local Offset = CF.new(CameraCFrame.p, CameraFocus.p)
	self.Recoil:update(delta)

	--	local Direction = (Offset.p - self.Head.Position).Unit * (self.CameraOffset).Magnitude
	--	local createRay = ray.new(self.Head.Position, Direction)
	--	local hit, position = workspace:FindPartOnRay(createRay, self.Character, false, true)
	currentCamera.CFrame = Offset * CFrame.fromEulerAnglesYXZ(self.Recoil.p.Y, self.Recoil.p.Z, 0)
	--	if hit and canOcclude(hit) then
	--		local distance = (position - self.SubjectRoot.Position).Magnitude
	--		currentCamera.CFrame = CF.new(Offset.p * -distance)
	--	end

	if self.Aiming == true then
		local NewCF = CF.new(self.SubjectRoot.CFrame.Position, self.SubjectRoot.CFrame.Position + V3.new(currentCamera.CFrame.LookVector.X, 0, currentCamera.CFrame.LookVector.Z))
		TweenService:Create(self.SubjectRoot, Infos.RootLerp, {["CFrame"] = NewCF}, true):Play()
	end
end

return Camera

now when I change the Mouse Behaviours on line 66 and 96 to “Default”

local Meta = {__index = Camera}
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInput = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local OriginalSense = UserInput.MouseDeltaSensitivity
local currentCamera = workspace.CurrentCamera
local Utilities = script:FindFirstAncestorWhichIsA("Folder")
local RecSpring = require(Utilities:WaitForChild("RecoilSpring"))

local PlayerGui = Players.LocalPlayer:WaitForChild("PlayerGui")
local ScreenDistortions = PlayerGui:WaitForChild("Distortions")

local MinTransparency = .25
local LeftShoulderPos = Vector3.new(3.5, 0, 6)
local RightShoulderPos = Vector3.new(-3.5, 0, 6)
UserInput.MouseIconEnabled = true

local Camerabind = "OTSCamera"
local Enabled = true
local Binded = {}
local Connections = {}
local Infos = {
	SwapShoulder = TweenInfo.new(
		.5,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	);
	AimLerp = TweenInfo.new(
		.4,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	);
	RootLerp = TweenInfo.new(
		.1,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	);
}

-- Localized Globals
local ray = Ray
local CF = CFrame
local V3 = Vector3
local rad = math.rad
local clamp = math.clamp

local DistortIn = TweenService:Create(ScreenDistortions.CleanDistort, Infos.AimLerp, {ImageTransparency = .3})
local DistortOut = TweenService:Create(ScreenDistortions.CleanDistort, Infos.AimLerp, {ImageTransparency = 1})

local function Initilization(self)
	if Binded[Camerabind] then return end
	currentCamera.CameraType = Enum.CameraType.Scriptable
	UserInput.MouseIconEnabled = true
	BindToRenderStep(Camerabind, Enum.RenderPriority.Camera.Value, function(delta)
		UserInput.MouseBehavior = Enum.MouseBehavior.Default
		self:Update(delta)
	end)
	table.insert(Connections, UserInput.InputChanged:Connect(function(input)
		trackInput(input, self)
	end))
	table.insert(Connections, self.Humanoid.Died:Connect(function()
		self:SetEnabled(false)
	end))
end

function BindToRenderStep(key, priority, func)
	Binded[key] = func

	RunService:BindToRenderStep(key, priority, func)
end

function UnbindFromRenderStep(key, self)
	RunService:UnbindFromRenderStep(key)
	if Binded[key] then
		Binded[key] = nil
	end
	for _, Connection in pairs(Connections) do
		Connection:Disconnect()
	end
	Connections = {}
	self.Humanoid.AutoRotate = true
	self.Aiming = false
	DistortOut:Play()	
	currentCamera.CameraType = Enum.CameraType.Custom
	UserInput.MouseBehavior = Enum.MouseBehavior.Default
	UserInput.MouseDeltaSensitivity = OriginalSense
	UserInput.MouseIconEnabled = true
end

function trackInput(input, self)
	if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
		self.XAngle = self.XAngle - input.Delta.X * .4
		self.YAngle = clamp(self.YAngle - input.Delta.Y * .4, -80, 80)
	end
end

function Camera.new(Character)
	local self = {}

	self.Character = Character
	self.SubjectRoot = Character.HumanoidRootPart
	self.Head = Character.Head
	self.Humanoid = self.Character:FindFirstChildOfClass("Humanoid")
	self.IsAlive = self.Humanoid:GetState() ~= Enum.HumanoidStateType.Dead

	self.XAngle = 0
	self.YAngle = 0
	self.Recoil = RecSpring.new(Vector3.new(), Vector3.new(), Vector3.new(), 20, 1)
	self.CameraOffset = script:WaitForChild('DefaultCameraPos') -- default location
	self.BaseFOV = currentCamera.FieldOfView
	self.Aiming = false

	self.Shoulder = "Left"
	self.RightTween = TweenService:Create(self.CameraOffset, Infos.SwapShoulder, {Value = RightShoulderPos})
	self.LeftTween = TweenService:Create(self.CameraOffset, Infos.SwapShoulder, {Value = LeftShoulderPos})

	Initilization(self) -- default behavior when u first call .new()
	return setmetatable(self, Meta)
end

function canOcclude(part)
	return part.Transparency < MinTransparency and part.CanCollide and not part:IsA("TrussPart")
end

function Camera:SetEnabled(boolean)
	if boolean ~= Enabled then
		Enabled = boolean
	end
	if Enabled == false and Binded[Camerabind] then
		UnbindFromRenderStep(Camerabind, self)
	elseif Enabled == true and not Binded[Camerabind] then
		Initilization(self)
	end
end

function Camera:UpdateADS(boolean, value)
	if self.Aiming ~= boolean then
		self.Aiming = boolean
	end
	if boolean == true then
		self.Humanoid.AutoRotate = false
		UserInput.MouseIconEnabled = true
		UserInput.MouseDeltaSensitivity = UserInput.MouseDeltaSensitivity/2.8
		TweenService:Create(currentCamera, Infos.AimLerp, {FieldOfView = value}):Play()
		DistortIn:Play()
	elseif boolean == false then
		self.Humanoid.AutoRotate = true
		UserInput.MouseIconEnabled = true
		UserInput.MouseDeltaSensitivity = OriginalSense
		TweenService:Create(currentCamera, Infos.AimLerp, {FieldOfView = self.BaseFOV}):Play()
		DistortOut:Play()
	end
end

function Camera:SwapShoulders(side)
	if self.Shoulder == "Right" and side == "Left" then
		self.LeftTween:Play()
	elseif self.Shoulder == "Left" and side == "Right" then
		self.RightTween:Play()
	end
	self.Shoulder = side
end

function Camera:Update(delta)
	if not self.IsAlive then self:SetEnabled(false) return end
	local CameraOffset = self.CameraOffset.Value
	local StartCFrame = CF.new((self.SubjectRoot.CFrame.Position + V3.new(0, 2, 0))) * CF.Angles(0, rad(self.XAngle), 0) * CF.Angles(rad(self.YAngle), 0, 0)

	local CameraCFrame = StartCFrame + StartCFrame:VectorToWorldSpace(V3.new(CameraOffset.X, CameraOffset.Y, CameraOffset.Z))
	local CameraFocus = StartCFrame + StartCFrame:VectorToWorldSpace(V3.new(CameraOffset.X, CameraOffset.Y, -50000))
	local Offset = CF.new(CameraCFrame.p, CameraFocus.p)
	self.Recoil:update(delta)

	--	local Direction = (Offset.p - self.Head.Position).Unit * (self.CameraOffset).Magnitude
	--	local createRay = ray.new(self.Head.Position, Direction)
	--	local hit, position = workspace:FindPartOnRay(createRay, self.Character, false, true)
	currentCamera.CFrame = Offset * CFrame.fromEulerAnglesYXZ(self.Recoil.p.Y, self.Recoil.p.Z, 0)
	--	if hit and canOcclude(hit) then
	--		local distance = (position - self.SubjectRoot.Position).Magnitude
	--		currentCamera.CFrame = CF.new(Offset.p * -distance)
	--	end

	if self.Aiming == true then
		local NewCF = CF.new(self.SubjectRoot.CFrame.Position, self.SubjectRoot.CFrame.Position + V3.new(currentCamera.CFrame.LookVector.X, 0, currentCamera.CFrame.LookVector.Z))
		TweenService:Create(self.SubjectRoot, Infos.RootLerp, {["CFrame"] = NewCF}, true):Play()
	end
end

return Camera

This is what happens

Whats going on and how do I fix this…

Explain each of your variables, your names are a little unclear.
In addition to that, how are you changing the cam position?

Very vague, do you know what I can change in the script.

Well if you tell me how are changing cam position then yes, I can help you.

The script defines a Camera class with methods for updating the camera position and orientation based on player input, as well as switching between left and right shoulder views. The camera also has an aiming mode which adjusts the FOV and adds screen distortions when active.

The script uses several services provided by the Roblox game engine such as Players, UserInputService, TweenService, and RunService. It also requires a RecoilSpring module for handling camera recoil.

The Camera.new() method creates a new camera instance for a specified character. The camera is initialized with default settings and behavior, and the player’s input is tracked to update the camera position and orientation accordingly. The camera can also be enabled or disabled using the Camera:SetEnabled(boolean) method.

The script also defines helper functions for binding and unbinding the camera to the game engine’s rendering loop, as well as tracking player input and determining which parts of the game environment should occlude the camera.

Oh nice, what is going on here is that LockCenter internally moves your character around based on the mouse delta(how much its moved every second).

This is why your character isn’t rotating anymore, Default mode doesn’t auto rotate your character.
Mouse.LockCenter is essentially shift lock.

Do you know a potential fix for this?

I don’t think there is one, this is the intended behavior.

What are you intending to be the behavior?

When the camera is on default, it moves normally, like intended in all roblox games.

Yes because you set it to the default.
Because you set it to the default, it will be the normal(default) movement.
You can’t really have this not happen.

Then is it possible to change it…

No, the two behaviors you have in your two videos are the only options.

You could switch between them if thats what you are meaning.(for stuff like whenever you open a gui)

Wouldnt it make sense to change it? From default to smt else…

But why would you change it from Shift lock mode(mousebehavior.LockCenter)???
It looks good and seems to work, and outside of moving mouse around for gui you don’t need to.
you aint gotta change anything it looks good quality and script works:+1:

Upon joining the game, I have menu’s, and it doesnt allow me to move my cursor at all?

So wouldn’t it be wise to change it?

No in that case it would.
Just allow the player to move it whenever they need to interact with a gui, and don’t let them when in combat mode.

So probably when the player presses the “play” button switch them into locked mode.

thats the thing, its a bit tedious. Should I disable the script when a GUI is opened? or clicked?

Whenever one is opened, clicked etc.
Just make it so that whenever you have a time to interact with a gui, turn off shift lock.
The exact details of how you detect that is up to you, and your gui scenario(mouse click gui, button click gui etc there are dif types)

You can go ahead and close this topic, the final details are up to you now.

Would be hard. What it should be, is when a weapon is equipped the SCRIPT should be enabled.