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

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)>.1 then
					local sPos=1
					if RStickX<0 then sPos=-1 end
					if intcam then
						CRot=sPos*math.abs(((math.abs(RStickX)-.1)/(.9)))*-80
					else
						CRot=sPos*math.abs(((math.abs(RStickX)-.1)/(.9)))*-90
					end
				else
					CRot=0
				end
				if math.abs(RStickY)>.1 then
					local sPos=1
					if RStickY<0 then sPos=-1 end
					if intcam then
						CUp=sPos*math.abs(((math.abs(RStickY)-.1)/(.9)))*30
					else
						CUp=math.min(sPos*math.abs(((math.abs(RStickY)-.1)/(.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=90 + (car.DriveSeat.Velocity.Magnitude/22)
				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=="z" then
			look=50
		elseif key=="x" then
			if intcam then
				look=-160
			else
				look=-180
			end
		elseif key=="c" 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=="z" and look==50 then
			look=0
		elseif key=="x" and (look==-160 or look==-180) then
			look=0
		elseif key=="c" 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)
