function DealWithInput(L,W)if UserInputService:GetFocusedTextBox()==nil and not _InControls then if _IsOn and L.KeyCode==_CTRL.ContlrPBrake or L.KeyCode==_CTRL.PBrake then if L.UserInputState==Enum.UserInputState.Begin then _PBrake=not _PBrake elseif L.UserInputState==Enum.UserInputState.End then if car.DriveSeat.Velocity.Magnitude>5 then _PBrake=false end end elseif _IsOn and(L.KeyCode==_CTRL.Throttle or L.KeyCode==_CTRL.Throttle2)then if L.UserInputState==Enum.UserInputState.Begin then _GThrot=1 else _GThrot=0 end elseif L.KeyCode==_CTRL.Brake or L.KeyCode==_CTRL.Brake2 then if L.UserInputState==Enum.UserInputState.Begin then _GBrake=1 else _GBrake=0 end elseif L.KeyCode==_CTRL.SteerLeft or L.KeyCode==_CTRL.SteerLeft2 then if L.UserInputState==Enum.UserInputState.Begin then _GSteerT=-1 _SteerL=true else if _SteerR then _GSteerT=1 else _GSteerT=0 end _SteerL=false end elseif L.KeyCode==_CTRL.SteerRight or L.KeyCode==_CTRL.SteerRight2 then if L.UserInputState==Enum.UserInputState.Begin then _GSteerT=1 _SteerR=true else if _SteerL then _GSteerT=-1 else _GSteerT=0 end _SteerR=false end end if L.UserInputType.Name:find("\071\097\109\101\112\097\100")then if L.KeyCode==_CTRL.ContlrSteer then if L.Position.X>=0 then local W=math.min(.99,_Tune.Peripherals.ControlRDZone/100)if math.abs(L.Position.X)>W then _GSteerT=(L.Position.X-W)/(1-W)else _GSteerT=0 end else local W=math.min(.99,_Tune.Peripherals.ControlLDZone/100)if math.abs(L.Position.X)>W then _GSteerT=(L.Position.X+W)/(1-W)else _GSteerT=0 end end elseif _IsOn and L.KeyCode==_CTRL.ContlrThrottle then _GThrot=L.Position.Z elseif L.KeyCode==_CTRL.ContlrBrake then _GBrake=L.Position.Z end end else _GThrot=0 _GSteerT=0 _GBrake=0 end end UserInputService.InputBegan:connect(DealWithInput)UserInputService.InputChanged:connect(DealWithInput)UserInputService.InputEnded:connect(DealWithInput)while wait()do script.Parent.Values.Throttle.Value=_GThrot script.Parent.Values.Brake.Value=_GBrake script.Parent.Values.SteerT.Value=_GSteerT script.Parent.Values.PBrake.Value=_PBrake end

function DealWithInput(input,IsRobloxFunction)
	if (UserInputService:GetFocusedTextBox()==nil) and not _InControls then --Ignore when UI Focus
		--Toggle PBrake
		if _IsOn and input.KeyCode ==_CTRL["ContlrPBrake"] or 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
		
		--Throttle
		elseif _IsOn and (input.KeyCode==_CTRL["Throttle"] or input.KeyCode == _CTRL["Throttle2"]) then
			if input.UserInputState == Enum.UserInputState.Begin then _GThrot = 1 else _GThrot = 0 end
			
		--Brake
		elseif (input.KeyCode==_CTRL["Brake"] or input.KeyCode == _CTRL["Brake2"]) then
			if input.UserInputState == Enum.UserInputState.Begin then _GBrake = 1 else _GBrake = 0 end
			
		--Steer Left
		elseif (input.KeyCode==_CTRL["SteerLeft"] or input.KeyCode == _CTRL["SteerLeft2"]) then
			if input.UserInputState == Enum.UserInputState.Begin then
				_GSteerT = -1
				_SteerL = true
			else
				if _SteerR then _GSteerT = 1 else _GSteerT = 0 end 
				_SteerL = false
			end
		--Steer Right
		elseif (input.KeyCode==_CTRL["SteerRight"] or input.KeyCode == _CTRL["SteerRight2"]) then
			if input.UserInputState == Enum.UserInputState.Begin then
				_GSteerT = 1
				_SteerR = true
			else
				if _SteerL then _GSteerT = -1 else _GSteerT = 0 end 
				_SteerR = false
			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(.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(.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 = input.Position.Z
				
			--Gamepad Brake
			elseif input.KeyCode == _CTRL["ContlrBrake"] then
				_GBrake = input.Position.Z
			end
		end
	else
		_GThrot = 0
		_GSteerT = 0
		_GBrake = 0
	end
end
UserInputService.InputBegan:connect(DealWithInput)
UserInputService.InputChanged:connect(DealWithInput)
UserInputService.InputEnded:connect(DealWithInput)

while wait() do
	script.Parent.Values.Throttle.Value = _GThrot
	script.Parent.Values.Brake.Value = _GBrake
	script.Parent.Values.SteerT.Value = _GSteerT
	script.Parent.Values.PBrake.Value = _PBrake
end