local i=false local F=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local r=0 local G=0 local h=0 local A=0 local X=0 local C=0 local W=0 local E=0 local v=0 local q=0 local l=0 function DealWithInput(F,H)if i then if F.KeyCode==Enum.KeyCode.ButtonX then if F.UserInputState==Enum.UserInputState.Begin then C=1 elseif F.UserInputState==Enum.UserInputState.End then C=0 end elseif F.KeyCode==Enum.KeyCode.ButtonY then if F.UserInputState==Enum.UserInputState.Begin then W=1 elseif F.UserInputState==Enum.UserInputState.End then W=0 end elseif F.KeyCode==Enum.KeyCode.ButtonL1 then if F.UserInputState==Enum.UserInputState.Begin then E=1 elseif F.UserInputState==Enum.UserInputState.End then E=0 end elseif F.KeyCode==Enum.KeyCode.ButtonR1 then if F.UserInputState==Enum.UserInputState.Begin then v=1 elseif F.UserInputState==Enum.UserInputState.End then v=0 end elseif F.KeyCode==Enum.KeyCode.DPadLeft then if F.UserInputState==Enum.UserInputState.Begin then l=1 elseif F.UserInputState==Enum.UserInputState.End then l=0 end elseif F.KeyCode==Enum.KeyCode.ButtonR3 then if F.UserInputState==Enum.UserInputState.Begin then q=1 elseif F.UserInputState==Enum.UserInputState.End then q=0 end end if F.UserInputType.Name:find("\071\097\109\101\112\097\100")then if F.KeyCode==Enum.KeyCode.Thumbstick1 then r=F.Position.X elseif F.KeyCode==Enum.KeyCode.Thumbstick2 then G=F.Position.X h=F.Position.Y elseif F.KeyCode==Enum.KeyCode.ButtonR2 then A=F.Position.Z elseif F.KeyCode==Enum.KeyCode.ButtonL2 then X=F.Position.Z end end end end F.InputBegan:connect(DealWithInput)F.InputChanged:connect(DealWithInput)F.InputEnded:connect(DealWithInput)car.DriveSeat.ChildRemoved:connect(function(i)if i.Name=="\083\101\097\116\087\101\108\100"then for i,F in pairs(Binded)do run:UnbindFromRenderStep(F)end workspace.CurrentCamera.CameraType=Enum.CameraType.Custom workspace.CurrentCamera.FieldOfView=70 player.CameraMaxZoomDistance=200 end end)function Camera()local i=workspace.CurrentCamera local F=false local r=0 local A=0 local X=0 local C=0 local W=0 local E=0 local function v()if not pcall(function()if E==0 and l==1 then F=not F end E=l if C==1 then if math.abs(G)>.1 then local i=1 if G<0 then i=-1 end if F then r=(i*math.abs((math.abs(G)-.1)/.9))*-80 else r=(i*math.abs((math.abs(G)-.1)/.9))*-90 end else r=0 end if math.abs(h)>.1 then local i=1 if h<0 then i=-1 end if F then X=(i*math.abs((math.abs(h)-.1)/.9))*30 else X=math.min((i*math.abs((math.abs(h)-.1)/.9))*-75,30)end else X=0 end else if r>W then r=math.max(W,r-20)elseif r<W then r=math.min(W,r+20)end X=0 end if F then A=0 else A=-180*q end if F then i.CameraSubject=player.Character.Humanoid i.CameraType=Enum.CameraType.Scriptable i.FieldOfView=80+car.DriveSeat.Velocity.Magnitude/12 player.CameraMaxZoomDistance=5 local F=car.Body.Cam.CFrame if q==1 then F=car.Body.RCam.CFrame end i.CoordinateFrame=(F*CFrame.Angles(0,math.rad(r+A),0))*CFrame.Angles(math.rad(X),0,0)else i.CameraSubject=car.DriveSeat i.FieldOfView=70 if C==0 then i.CameraType=Enum.CameraType.Custom player.CameraMaxZoomDistance=400 run:UnbindFromRenderStep("\067\097\109\085\112\100\097\116\101")else i.CameraType="\083\099\114\105\112\116\097\098\108\101"local F=math.min(1,car.DriveSeat.Velocity.Magnitude/500)local G=((car.DriveSeat.Position+Vector3.new(0,8+F*2,0))-(car.DriveSeat.CFrame*CFrame.Angles(math.rad(X),math.rad(r+A),0)).lookVector*17)+(car.DriveSeat.Velocity.Unit*-7)*F i.CoordinateFrame=CFrame.new(G,car.DriveSeat.Position)end end end)then i.FieldOfView=70 i.CameraSubject=player.Character.Humanoid i.CameraType=Enum.CameraType.Custom player.CameraMaxZoomDistance=400 run:UnbindFromRenderStep("\067\097\109\085\112\100\097\116\101")end end local function H()if GMode~=C then C=GMode run:BindToRenderStep("\067\097\109\085\112\100\097\116\101",Enum.RenderPriority.Camera.Value,v)end end mouse.KeyDown:connect(function(i)if i=="\116"then W=50 elseif i=="\121"then if F then W=-160 else W=-180 end elseif i=="\117"then W=-50 elseif i=="\118"then run:UnbindFromRenderStep("\067\097\109\085\112\100\097\116\101")F=not F run:BindToRenderStep("\067\097\109\085\112\100\097\116\101",Enum.RenderPriority.Camera.Value,v)end end)mouse.KeyUp:connect(function(i)if i=="\116"and W==50 then W=0 elseif i=="\121"and(W==-160 or W==-180)then W=0 elseif i=="\117"and W==-50 then W=0 end end)run:BindToRenderStep("\067\077\067\104\097\110\103\101",Enum.RenderPriority.Camera.Value,H)table.insert(Binded,"\067\097\109\085\112\100\097\116\101")table.insert(Binded,"\067\077\067\104\097\110\103\101")end Camera()mouse.KeyDown:connect(function(F)if F=="\098"then if GMode>=1 then GMode=0 else GMode=GMode+1 end if GMode==1 then i=true else i=false end end end)
---Controller
local Controller = false
local UserInputService = game:GetService("UserInputService")
local LStickX = 0
local RStickX = 0
local RStickY = 0
local RTriggerValue = 0
local LTriggerValue = 0

local ButtonX = 0
local ButtonY = 0
local ButtonL1 = 0
local ButtonR1 = 0
local ButtonR3 = 0
local DPadUp = 0
function DealWithInput(input, IsRobloxFunction)
	if Controller then
		if input.KeyCode == Enum.KeyCode.ButtonX then
			if input.UserInputState == Enum.UserInputState.Begin then
				ButtonX = 1
			elseif input.UserInputState == Enum.UserInputState.End then
				ButtonX = 0
			end
		elseif input.KeyCode == Enum.KeyCode.ButtonY then
			if input.UserInputState == Enum.UserInputState.Begin then
				ButtonY = 1
			elseif input.UserInputState == Enum.UserInputState.End then
				ButtonY = 0
			end
		elseif input.KeyCode == Enum.KeyCode.ButtonL1 then
			if input.UserInputState == Enum.UserInputState.Begin then
				ButtonL1 = 1
			elseif input.UserInputState == Enum.UserInputState.End then
				ButtonL1 = 0
			end
		elseif input.KeyCode == Enum.KeyCode.ButtonR1 then
			if input.UserInputState == Enum.UserInputState.Begin then
				ButtonR1 = 1
			elseif input.UserInputState == Enum.UserInputState.End then
				ButtonR1 = 0
			end
		elseif input.KeyCode == Enum.KeyCode.DPadLeft then
			if input.UserInputState == Enum.UserInputState.Begin then
				DPadUp = 1
			elseif input.UserInputState == Enum.UserInputState.End then
				DPadUp = 0
			end
		elseif input.KeyCode == Enum.KeyCode.ButtonR3 then
			if input.UserInputState == Enum.UserInputState.Begin then
				ButtonR3 = 1
			elseif input.UserInputState == Enum.UserInputState.End then
				ButtonR3 = 0
			end
		end
		if input.UserInputType.Name:find("Gamepad") then --it's one of 4 gamepads
			if input.KeyCode == Enum.KeyCode.Thumbstick1 then
				LStickX = input.Position.X
			elseif input.KeyCode == Enum.KeyCode.Thumbstick2 then
				RStickX = input.Position.X
				RStickY = input.Position.Y
			elseif input.KeyCode == Enum.KeyCode.ButtonR2 then --right shoulder
				RTriggerValue = input.Position.Z
			elseif input.KeyCode == Enum.KeyCode.ButtonL2 then --left shoulder
				LTriggerValue = input.Position.Z
			end
		end
	end
end
UserInputService.InputBegan:connect(DealWithInput)
UserInputService.InputChanged:connect(DealWithInput) --keyboards don't activate with Changed, only Begin and Ended. idk if digital controller buttons do too
UserInputService.InputEnded:connect(DealWithInput)

car.DriveSeat.ChildRemoved:connect(function(child)
	if child.Name == "SeatWeld" then
		for i, v in pairs(Binded) do
			run:UnbindFromRenderStep(v)
		end
		workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
		workspace.CurrentCamera.FieldOfView = 70
		player.CameraMaxZoomDistance = 200
	end
end)

function Camera()
	local cam = workspace.CurrentCamera
	local intcam = false
	local CRot = 0
	local CBack = 0
	local CUp = 0
	local mode = 0
	local look = 0
	local camChange = 0
	local function CamUpdate()
		if
			not pcall(function()
				if camChange == 0 and DPadUp == 1 then
					intcam = not intcam
				end
				camChange = DPadUp
				if mode == 1 then
					if math.abs(RStickX) > 0.1 then
						local sPos = 1
						if RStickX < 0 then
							sPos = -1
						end
						if intcam then
							CRot = sPos * math.abs(((math.abs(RStickX) - 0.1) / 0.9)) * -80
						else
							CRot = sPos * math.abs(((math.abs(RStickX) - 0.1) / 0.9)) * -90
						end
					else
						CRot = 0
					end
					if math.abs(RStickY) > 0.1 then
						local sPos = 1
						if RStickY < 0 then
							sPos = -1
						end
						if intcam then
							CUp = sPos * math.abs(((math.abs(RStickY) - 0.1) / 0.9)) * 30
						else
							CUp = math.min(sPos * math.abs(((math.abs(RStickY) - 0.1) / 0.9)) * -75, 30)
						end
					else
						CUp = 0
					end
				else
					if CRot > look then
						CRot = math.max(look, CRot - 20)
					elseif CRot < look then
						CRot = math.min(look, CRot + 20)
					end
					CUp = 0
				end
				if intcam then
					CBack = 0
				else
					CBack = -180 * ButtonR3
				end
				if intcam then
					cam.CameraSubject = player.Character.Humanoid
					cam.CameraType = Enum.CameraType.Scriptable
					cam.FieldOfView = 80 + car.DriveSeat.Velocity.Magnitude / 12
					player.CameraMaxZoomDistance = 5
					local cf = car.Body.Cam.CFrame
					if ButtonR3 == 1 then
						cf = car.Body.RCam.CFrame
					end
					cam.CoordinateFrame = cf
						* CFrame.Angles(0, math.rad(CRot + CBack), 0)
						* CFrame.Angles(math.rad(CUp), 0, 0)
				else
					cam.CameraSubject = car.DriveSeat
					cam.FieldOfView = 70
					if mode == 0 then
						cam.CameraType = Enum.CameraType.Custom
						player.CameraMaxZoomDistance = 400
						run:UnbindFromRenderStep("CamUpdate")
					else
						cam.CameraType = "Scriptable"
						local pspeed = math.min(1, car.DriveSeat.Velocity.Magnitude / 500)
						local cc = car.DriveSeat.Position
							+ Vector3.new(0, 8 + (pspeed * 2), 0)
							- ((car.DriveSeat.CFrame * CFrame.Angles(math.rad(CUp), math.rad(CRot + CBack), 0)).lookVector * 17)
							+ (car.DriveSeat.Velocity.Unit * -7 * pspeed)
						cam.CoordinateFrame = CFrame.new(cc, car.DriveSeat.Position)
					end
				end
			end)
		then
			cam.FieldOfView = 70
			cam.CameraSubject = player.Character.Humanoid
			cam.CameraType = Enum.CameraType.Custom
			player.CameraMaxZoomDistance = 400
			run:UnbindFromRenderStep("CamUpdate")
		end
	end
	local function ModeChange()
		if GMode ~= mode then
			mode = GMode
			run:BindToRenderStep("CamUpdate", Enum.RenderPriority.Camera.Value, CamUpdate)
		end
	end
	mouse.KeyDown:connect(function(key)
		if key == "t" then
			look = 50
		elseif key == "y" then
			if intcam then
				look = -160
			else
				look = -180
			end
		elseif key == "u" then
			look = -50
		elseif key == "v" then
			run:UnbindFromRenderStep("CamUpdate")
			intcam = not intcam
			run:BindToRenderStep("CamUpdate", Enum.RenderPriority.Camera.Value, CamUpdate)
		end
	end)
	mouse.KeyUp:connect(function(key)
		if key == "t" and look == 50 then
			look = 0
		elseif key == "y" and (look == -160 or look == -180) then
			look = 0
		elseif key == "u" and look == -50 then
			look = 0
		end
	end)
	run:BindToRenderStep("CMChange", Enum.RenderPriority.Camera.Value, ModeChange)
	table.insert(Binded, "CamUpdate")
	table.insert(Binded, "CMChange")
end
Camera()

mouse.KeyDown:connect(function(key)
	if key == "b" then
		if GMode >= 1 then
			GMode = 0
		else
			GMode = GMode + 1
		end
		if GMode == 1 then
			Controller = true
		else
			Controller = false
		end
	end
end)
