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…