function DealWithInput(G,n)if UserInputService:GetFocusedTextBox()==nil and not _InControls then if _IsOn and((G.KeyCode==_CTRL.ContlrShiftDown or _MSteer and G.KeyCode==_CTRL.MouseShiftDown or not _MSteer and G.KeyCode==_CTRL.ShiftDown)and((_TMode=="\083\101\109\105"or _TMode=="\077\097\110\117\097\108"and not _ClutchOn)and G.UserInputState==Enum.UserInputState.Begin))then if _CGear==0 and(_TMode=="\065\117\116\111"or not _ClPressing)then _ClutchOn=true end _CGear=math.max(_CGear-1,-1)elseif _IsOn and((G.KeyCode==_CTRL.ContlrShiftUp or _MSteer and G.KeyCode==_CTRL.MouseShiftUp or not _MSteer and G.KeyCode==_CTRL.ShiftUp)and((_TMode=="\083\101\109\105"or _TMode=="\077\097\110\117\097\108"and not _ClutchOn)and G.UserInputState==Enum.UserInputState.Begin))then if _CGear==0 and(_TMode=="\065\117\116\111"or not _ClPressing)then _ClutchOn=true end _CGear=math.min(_CGear+1,#_Tune.Ratios-2)elseif _IsOn and((G.KeyCode==_CTRL.ContlrClutch or _MSteer and G.KeyCode==_CTRL.MouseClutch or not _MSteer and G.KeyCode==_CTRL.Clutch)and _TMode=="\077\097\110\117\097\108")then if G.UserInputState==Enum.UserInputState.Begin then _ClutchOn=false _ClPressing=true elseif G.UserInputState==Enum.UserInputState.End then _ClutchOn=true _ClPressing=false end elseif _IsOn and G.KeyCode==_CTRL.ContlrPBrake or _MSteer and G.KeyCode==_CTRL.MousePBrake or not _MSteer and G.KeyCode==_CTRL.PBrake then if G.UserInputState==Enum.UserInputState.Begin then _PBrake=not _PBrake elseif G.UserInputState==Enum.UserInputState.End then if car.DriveSeat.Velocity.Magnitude>5 then _PBrake=false end end elseif(G.KeyCode==_CTRL.ContlrToggleTMode or G.KeyCode==_CTRL.ToggleTransMode)and G.UserInputState==Enum.UserInputState.Begin then local G=1 for n,Q in pairs(_Tune.TransModes)do if Q==_TMode then G=n break end end G=G+1 if G>#_Tune.TransModes then G=1 end _TMode=_Tune.TransModes[G]elseif _IsOn and(not _MSteer and(G.KeyCode==_CTRL.Throttle or G.KeyCode==_CTRL.Throttle2))or((_CTRL.MouseThrottle==Enum.UserInputType.MouseButton1 or _CTRL.MouseThrottle==Enum.UserInputType.MouseButton2)and G.UserInputType==_CTRL.MouseThrottle or G.KeyCode==_CTRL.MouseThrottle)and _MSteer then if game.Players.LocalPlayer.PlayerGui["\065-\067\104\097\115\115\105\115 \073\110\116\101\114\102\097\099\101"].AC6_Stock_Gauges.SelfDrive:GetAttribute("\069\110\097\098\108\101\100")==false then if G.UserInputState==Enum.UserInputState.Begin then _GThrot=1 else _GThrot=_Tune.IdleThrottle/100 end end elseif not _MSteer and(G.KeyCode==_CTRL.Brake or G.KeyCode==_CTRL.Brake2)or((_CTRL.MouseBrake==Enum.UserInputType.MouseButton1 or _CTRL.MouseBrake==Enum.UserInputType.MouseButton2)and G.UserInputType==_CTRL.MouseBrake or G.KeyCode==_CTRL.MouseBrake)and _MSteer then if game.Players.LocalPlayer.PlayerGui["\065-\067\104\097\115\115\105\115 \073\110\116\101\114\102\097\099\101"].AC6_Stock_Gauges.SelfDrive:GetAttribute("\069\110\097\098\108\101\100")==false then if G.UserInputState==Enum.UserInputState.Begin then _GBrake=1 else _GBrake=0 end end elseif not _MSteer and(G.KeyCode==_CTRL.SteerLeft or G.KeyCode==_CTRL.SteerLeft2)then if G.UserInputState==Enum.UserInputState.Begin then _GSteerC=-1 _SteerL=true else if _SteerR then _GSteerC=1 else _GSteerC=0 end _SteerL=false end elseif not _MSteer and(G.KeyCode==_CTRL.SteerRight or G.KeyCode==_CTRL.SteerRight2)then if G.UserInputState==Enum.UserInputState.Begin then _GSteerC=1 _SteerR=true else if _SteerL then _GSteerC=-1 else _GSteerC=0 end _SteerR=false end elseif G.KeyCode==_CTRL.ToggleMouseDrive then if G.UserInputState==Enum.UserInputState.End then _MSteer=not _MSteer _GThrot=_Tune.IdleThrottle/100 _GBrake=0 _GSteerT=0 _ClutchOn=true end elseif _Tune.TCSEnabled and(_IsOn and G.KeyCode==_CTRL.ToggleTCS)or G.KeyCode==_CTRL.ContlrToggleTCS then if G.UserInputState==Enum.UserInputState.End then _TCS=not _TCS end elseif _Tune.ABSEnabled and(_IsOn and G.KeyCode==_CTRL.ToggleABS)or G.KeyCode==_CTRL.ContlrToggleABS then if G.UserInputState==Enum.UserInputState.End then _ABS=not _ABS end end if G.UserInputType.Name:find("\071\097\109\101\112\097\100")then if G.KeyCode==_CTRL.ContlrSteer then if G.Position.X>=0 then local n=math.min(.99,_Tune.Peripherals.ControlRDZone/100)if math.abs(G.Position.X)>n then _GSteerT=(G.Position.X-n)/(1-n)else _GSteerT=0 end else local n=math.min(.99,_Tune.Peripherals.ControlLDZone/100)if math.abs(G.Position.X)>n then _GSteerT=(G.Position.X+n)/(1-n)else _GSteerT=0 end end elseif _IsOn and G.KeyCode==_CTRL.ContlrThrottle then _GThrot=math.max(_Tune.IdleThrottle/100,G.Position.Z)elseif G.KeyCode==_CTRL.ContlrBrake then _GBrake=G.Position.Z end end else _GThrot=_Tune.IdleThrottle/100 _GSteerT=0 _GBrake=0 if _CGear~=0 then _ClutchOn=true end end end UserInputService.InputBegan:connect(DealWithInput)UserInputService.InputChanged:connect(DealWithInput)UserInputService.InputEnded:connect(DealWithInput)
--Input Handler
function DealWithInput(input, IsRobloxFunction)
	if (UserInputService:GetFocusedTextBox() == nil) and not _InControls then --Ignore when UI Focus
		--Shift Down [Manual Transmission]
		if
			_IsOn
			and (input.KeyCode == _CTRL["ContlrShiftDown"] or (_MSteer and input.KeyCode == _CTRL["MouseShiftDown"]) or ((not _MSteer) and input.KeyCode == _CTRL["ShiftDown"]))
			and (_TMode == "Semi" or (_TMode == "Manual" and not _ClutchOn))
			and input.UserInputState == Enum.UserInputState.Begin
		then
			if _CGear == 0 and (_TMode == "Auto" or not _ClPressing) then
				_ClutchOn = true
			end
			_CGear = math.max(_CGear - 1, -1)

			--Shift Up [Manual Transmission]
		elseif
			_IsOn
			and (input.KeyCode == _CTRL["ContlrShiftUp"] or (_MSteer and input.KeyCode == _CTRL["MouseShiftUp"]) or ((not _MSteer) and input.KeyCode == _CTRL["ShiftUp"]))
			and (_TMode == "Semi" or (_TMode == "Manual" and not _ClutchOn))
			and input.UserInputState == Enum.UserInputState.Begin
		then
			if _CGear == 0 and (_TMode == "Auto" or not _ClPressing) then
				_ClutchOn = true
			end
			_CGear = math.min(_CGear + 1, #_Tune.Ratios - 2)

			--Toggle Clutch
		elseif
			_IsOn
			and (input.KeyCode == _CTRL["ContlrClutch"] or (_MSteer and input.KeyCode == _CTRL["MouseClutch"]) or ((not _MSteer) and input.KeyCode == _CTRL["Clutch"]))
			and _TMode == "Manual"
		then
			if input.UserInputState == Enum.UserInputState.Begin then
				_ClutchOn = false
				_ClPressing = true
			elseif input.UserInputState == Enum.UserInputState.End then
				_ClutchOn = true
				_ClPressing = false
			end

			--Toggle PBrake
		elseif
			_IsOn and input.KeyCode == _CTRL["ContlrPBrake"]
			or (_MSteer and input.KeyCode == _CTRL["MousePBrake"])
			or ((not _MSteer) and input.KeyCode == _CTRL["PBrake"])
		then
			if input.UserInputState == Enum.UserInputState.Begin then
				_PBrake = not _PBrake
			elseif input.UserInputState == Enum.UserInputState.End then
				if car.DriveSeat.Velocity.Magnitude > 5 then
					_PBrake = false
				end
			end

			--Toggle Transmission Mode
		elseif
			(input.KeyCode == _CTRL["ContlrToggleTMode"] or input.KeyCode == _CTRL["ToggleTransMode"])
			and input.UserInputState == Enum.UserInputState.Begin
		then
			local n = 1
			for i, v in pairs(_Tune.TransModes) do
				if v == _TMode then
					n = i
					break
				end
			end
			n = n + 1
			if n > #_Tune.TransModes then
				n = 1
			end
			_TMode = _Tune.TransModes[n]

			--Throttle
		elseif
			_IsOn and ((not _MSteer) and (input.KeyCode == _CTRL["Throttle"] or input.KeyCode == _CTRL["Throttle2"]))
			or (
				(
					(
						(
							_CTRL["MouseThrottle"] == Enum.UserInputType.MouseButton1
							or _CTRL["MouseThrottle"] == Enum.UserInputType.MouseButton2
						) and input.UserInputType == _CTRL["MouseThrottle"]
					) or input.KeyCode == _CTRL["MouseThrottle"]
				) and _MSteer
			)
		then
			if
				game.Players.LocalPlayer.PlayerGui["A-Chassis Interface"].AC6_Stock_Gauges.SelfDrive:GetAttribute(
					"Enabled"
				) == false
			then
				if input.UserInputState == Enum.UserInputState.Begin then
					_GThrot = 1
				else
					_GThrot = _Tune.IdleThrottle / 100
				end
			end

			--Brake
		elseif
			((not _MSteer) and (input.KeyCode == _CTRL["Brake"] or input.KeyCode == _CTRL["Brake2"]))
			or (
				(
					(
						(
							_CTRL["MouseBrake"] == Enum.UserInputType.MouseButton1
							or _CTRL["MouseBrake"] == Enum.UserInputType.MouseButton2
						) and input.UserInputType == _CTRL["MouseBrake"]
					) or input.KeyCode == _CTRL["MouseBrake"]
				) and _MSteer
			)
		then
			if
				game.Players.LocalPlayer.PlayerGui["A-Chassis Interface"].AC6_Stock_Gauges.SelfDrive:GetAttribute(
					"Enabled"
				) == false
			then
				if input.UserInputState == Enum.UserInputState.Begin then
					_GBrake = 1
				else
					_GBrake = 0
				end
			end

			--Steer Left
		elseif (not _MSteer) and (input.KeyCode == _CTRL["SteerLeft"] or input.KeyCode == _CTRL["SteerLeft2"]) then
			if input.UserInputState == Enum.UserInputState.Begin then
				_GSteerC = -1
				_SteerL = true
			else
				if _SteerR then
					_GSteerC = 1
				else
					_GSteerC = 0
				end
				_SteerL = false
			end

			--Steer Right
		elseif (not _MSteer) and (input.KeyCode == _CTRL["SteerRight"] or input.KeyCode == _CTRL["SteerRight2"]) then
			if input.UserInputState == Enum.UserInputState.Begin then
				_GSteerC = 1
				_SteerR = true
			else
				if _SteerL then
					_GSteerC = -1
				else
					_GSteerC = 0
				end
				_SteerR = false
			end

			--Toggle Mouse Controls
		elseif input.KeyCode == _CTRL["ToggleMouseDrive"] then
			if input.UserInputState == Enum.UserInputState.End then
				_MSteer = not _MSteer
				_GThrot = _Tune.IdleThrottle / 100
				_GBrake = 0
				_GSteerT = 0
				_ClutchOn = true
			end

			--Toggle TCS
		elseif
			_Tune.TCSEnabled and _IsOn and input.KeyCode == _CTRL["ToggleTCS"]
			or input.KeyCode == _CTRL["ContlrToggleTCS"]
		then
			if input.UserInputState == Enum.UserInputState.End then
				_TCS = not _TCS
			end

			--Toggle ABS
		elseif
			_Tune.ABSEnabled and _IsOn and input.KeyCode == _CTRL["ToggleABS"]
			or input.KeyCode == _CTRL["ContlrToggleABS"]
		then
			if input.UserInputState == Enum.UserInputState.End then
				_ABS = not _ABS
			end
		end

		--Variable Controls
		if input.UserInputType.Name:find("Gamepad") then
			--Gamepad Steering
			if input.KeyCode == _CTRL["ContlrSteer"] then
				if input.Position.X >= 0 then
					local cDZone = math.min(0.99, _Tune.Peripherals.ControlRDZone / 100)
					if math.abs(input.Position.X) > cDZone then
						_GSteerT = (input.Position.X - cDZone) / (1 - cDZone)
					else
						_GSteerT = 0
					end
				else
					local cDZone = math.min(0.99, _Tune.Peripherals.ControlLDZone / 100)
					if math.abs(input.Position.X) > cDZone then
						_GSteerT = (input.Position.X + cDZone) / (1 - cDZone)
					else
						_GSteerT = 0
					end
				end

				--Gamepad Throttle
			elseif _IsOn and input.KeyCode == _CTRL["ContlrThrottle"] then
				_GThrot = math.max(_Tune.IdleThrottle / 100, input.Position.Z)

				--Gamepad Brake
			elseif input.KeyCode == _CTRL["ContlrBrake"] then
				_GBrake = input.Position.Z
			end
		end
	else
		_GThrot = _Tune.IdleThrottle / 100
		_GSteerT = 0
		_GBrake = 0
		if _CGear ~= 0 then
			_ClutchOn = true
		end
	end
end
UserInputService.InputBegan:connect(DealWithInput)
UserInputService.InputChanged:connect(DealWithInput)
UserInputService.InputEnded:connect(DealWithInput)
