So I have a local script called "CameraScript" which overwrites the default script:
--services
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
--constants
local LOCAL_PLAYER = Players.LocalPlayer
local CAMERA = workspace.CurrentCamera
local CHARACTER = LOCAL_PLAYER.Character or LOCAL_PLAYER.CharacterAdded:Wait()
local HUMANOID = CHARACTER:WaitForChild("Humanoid")
local HUMANOID_ROOT_PART = HUMANOID.RootPart
local CHARACTERS = workspace:WaitForChild("Characters")
--variables
local x = 0
local y = 0
local vx = 0
local vy = 0
--functions
--initiate
CAMERA.FieldOfView = 80
CAMERA.CameraType = Enum.CameraType.Custom
CAMERA.CameraSubject = CHARACTER
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
RunService:BindToRenderStep("Camera", Enum.RenderPriority.Last.Value, function(dt)
CAMERA.Focus = CFrame.new(HUMANOID_ROOT_PART.Position)
x = (x - vx * (1/260)) % (math.pi * 2)
y = math.clamp(y - vy * (1/260), -1.4, 0.5)
local center = HUMANOID_ROOT_PART.Position + Vector3.new(0, 4, 0)
local cframe = CFrame.new(center) * CFrame.Angles(0, x, 0) * CFrame.Angles(y, 0, 0) * CFrame.new(0, 0, 20)
local rotation = cframe - cframe.p
local ray = Ray.new(center, (cframe.p - HUMANOID_ROOT_PART.Position))
local _, position = workspace:FindPartOnRayWithIgnoreList(ray, {})
CAMERA.CFrame = CFrame.new(position) * rotation
if vx < 0 then
vx = vx + 0.1
elseif vx > 0 then
vx = vx - 0.1
end
if vy < 0 then
vy = vy + 0.1
elseif vy > 0 then
vy = vy - 0.1
end
end)
UserInputService.InputChanged:connect(function(inputObject, processed)
if not processed then
if vx < 10 and vx > -10 then
vx = vx + inputObject.Delta.X * 0.05
end
if vy < 10 and vy > -10 then
vy = vy + inputObject.Delta.Y * 0.05
end
end
end)
LOCAL_PLAYER.CharacterAdded:Connect(function(character)
CHARACTER = LOCAL_PLAYER.Character or LOCAL_PLAYER.CharacterAdded:Wait()
HUMANOID = CHARACTER:WaitForChild("Humanoid")
HUMANOID_ROOT_PART = HUMANOID.RootPart
end)
The script works fine, but I don't know how to make the script also include a way to revert the player's camera back and forth the default third person camera. Any ideas?

1 comment
Hmm. That's a tricky one. Maybe you could try setting up a keybind that will make the camera script/function be temporarily disabled. Not sure if that would work or not, but I would give it a try anyway. Good luck on your game!