UsernameRTX

Advanced Driving Simulator Auto-farm

Aug 23rd, 2021
13,780
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local Players = game:GetService("Players")
  2. local CoreGui = game:GetService("CoreGui")
  3. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  4. local Debris = game:GetService("Debris")
  5. local HttpService = game:GetService("HttpService")
  6.  
  7. local raceColliders = workspace["$raceColliders"]
  8.  
  9. local LocalPlayer = Players.LocalPlayer
  10.  
  11. local PlayerGui = LocalPlayer.PlayerGui
  12.  
  13. local Races = PlayerGui.Races
  14.  
  15. local assets = ReplicatedStorage.assets
  16.  
  17. local assetsraces = assets.races
  18.  
  19. local remotes = ReplicatedStorage.remotes
  20.  
  21. local remotesraces = remotes.races
  22.  
  23. local RaceNotifier = remotesraces:FindFirstChild("RaceNotifier")
  24. if RaceNotifier then
  25.     RaceNotifier:Destroy()
  26. end
  27. local SignalInterest = remotesraces.SignalInterest
  28.  
  29. local src = ReplicatedStorage.src
  30.  
  31. local pcar = src.pcar
  32.  
  33. local CarInput = pcar.CarInput
  34.  
  35. local Keyboard = require(CarInput.Keyboard)
  36.  
  37. local CarPlacer = require(pcar.CarPlacer)
  38. local CarTracker = require(pcar.CarTracker)
  39. local ClientCarState = require(pcar.ClientCarState)
  40.  
  41. local prace = src.prace
  42.  
  43. local ClientRaceState = require(prace["ClientRaceState.client"])
  44.  
  45. local GetInactiveRaces = function(...)
  46.     local Children = assetsraces:GetChildren()
  47.     local InactiveRaces = {}
  48.     table.foreachi(Children, function(_, Value, ...)
  49.         local State = Value.State
  50.        
  51.         local RaceActive = State.RaceActive
  52.         if not RaceActive.Value then
  53.             table.insert(InactiveRaces, Value)
  54.             return
  55.         else
  56.             return
  57.         end
  58.     end)
  59.     return InactiveRaces
  60. end
  61.  
  62. local GetInactiveRacesTheLocalPlayerCanStart = function(...)
  63.     local InactiveRaces = GetInactiveRaces()
  64.     local InactiveRacesTheLocalPlayerCanStart = {}
  65.     table.foreachi(InactiveRaces, function(_, Value, ...)
  66.         local State = Value.State
  67.        
  68.         local NumPlayers = State.NumPlayers
  69.        
  70.         local Module = require(Value.Module)
  71.         if NumPlayers.Value >= Module.minPlayers - 1 then
  72.             table.insert(InactiveRacesTheLocalPlayerCanStart, Value)
  73.             return
  74.         else
  75.             return
  76.         end
  77.     end)
  78.     return InactiveRacesTheLocalPlayerCanStart
  79. end
  80.  
  81. local GetBestInactiveRaceId = function(...)
  82.     local InactiveRacesTheLocalPlayerCanStart = GetInactiveRacesTheLocalPlayerCanStart()
  83.     local earningsMultiplier = -math.huge
  84.     local BestInactiveRaceId = nil
  85.     table.foreachi(InactiveRacesTheLocalPlayerCanStart, function(_, Value, ...)
  86.         local Module = require(Value.Module)
  87.         if Module.earningsMultiplier > earningsMultiplier then
  88.             earningsMultiplier = Module.earningsMultiplier
  89.             BestInactiveRaceId = Value.Name
  90.             return
  91.         else
  92.             return
  93.         end
  94.     end)
  95.     return BestInactiveRaceId
  96. end
  97.  
  98. local ResetVelocityOfLocalPlayersCar = function(...)
  99.     local LocalPlayersCar = CarTracker.getCarFromDriver(LocalPlayer)
  100.     local Descendants = LocalPlayersCar:GetDescendants()
  101.     table.foreachi(Descendants, function(_, Value, ...)
  102.         if Value:IsA("BasePart") then
  103.             Value.AssemblyLinearVelocity = Vector3.new()
  104.             Value.AssemblyAngularVelocity = Vector3.new()
  105.             return
  106.         else
  107.             return
  108.         end
  109.     end)
  110.     return
  111. end
  112.  
  113. if ClientCarState.isDriving then
  114.     local LocalPlayersCar = CarTracker.getCarFromDriver(LocalPlayer)
  115.     if not LocalPlayersCar.PrimaryPart.Anchored then
  116.         LocalPlayersCar.PrimaryPart.Anchored = true
  117.     end
  118.     ResetVelocityOfLocalPlayersCar()
  119.    
  120.     local _, Size = LocalPlayersCar:GetBoundingBox()
  121.     local Part = Instance.new("Part")
  122.     Part.Name = HttpService:GenerateGUID(true)
  123.     Part.Parent = workspace
  124.     Part.Size = Vector3.new(Size.X, 1, 2048)
  125.     Part.Position = Vector3.new(0, -65.5, 0)
  126.     Part.Anchored = true
  127.    
  128.     CarPlacer.place(nil, LocalPlayersCar, Part.CFrame + Vector3.new(0, Part.Size.Y / 2 + Size.Y / 2, Part.Size.Z / 2 - Size.Z / 2))
  129.     if LocalPlayersCar.PrimaryPart.Anchored then
  130.         LocalPlayersCar.PrimaryPart.Anchored = false
  131.     end
  132.    
  133.     local CarInput = debug.getupvalue(Keyboard.GetNitro, 1)
  134.     local LocalPlayersCarPrimaryPart = LocalPlayersCar.PrimaryPart
  135.     local Debounce = false
  136.     local OldBestInactiveRaceId = nil
  137.    
  138.     while true do
  139.         if ClientRaceState.racing then
  140.             if CarInput.RightShift then
  141.                 CarInput.RightShift = false
  142.             end
  143.            
  144.             local HudContainer = Races:WaitForChild("HudContainer", math.huge)
  145.             if HudContainer then
  146.                 local assetsracesRace = assetsraces[OldBestInactiveRaceId]
  147.                
  148.                 local Checkpoints = assetsracesRace.Checkpoints
  149.                 local Module = require(assetsracesRace.Module)
  150.                
  151.                 local raceCollidersRace = raceColliders[OldBestInactiveRaceId]
  152.                
  153.                 local NumCheckpoints = raceCollidersRace.NumCheckpoints
  154.                
  155.                 for Index = 1, Module.laps do
  156.                     for Index2 = 1, NumCheckpoints.Value do
  157.                         local Checkpoint = Checkpoints[Index2]
  158.                        
  159.                         local ArrowRefCFrame = Checkpoint.ArrowRefCFrame
  160.                        
  161.                         CarPlacer.place(nil, LocalPlayersCar, ArrowRefCFrame.Value)
  162.                        
  163.                         Checkpoint = raceCollidersRace:WaitForChild(Index2, math.huge)
  164.                        
  165.                         CarPlacer.place(nil, LocalPlayersCar, Checkpoint.CFrame)
  166.                         task.wait(1)
  167.                     end
  168.                 end
  169.                 repeat
  170.                     task.wait()
  171.                 until not ClientRaceState.racing
  172.                
  173.                 if not LocalPlayersCar.PrimaryPart.Anchored then
  174.                     LocalPlayersCar.PrimaryPart.Anchored = true
  175.                 end
  176.                 ResetVelocityOfLocalPlayersCar()
  177.                 CarPlacer.place(nil, LocalPlayersCar, Part.CFrame + Vector3.new(0, Part.Size.Y / 2 + Size.Y / 2, Part.Size.Z / 2 - Size.Z / 2))
  178.                 if LocalPlayersCar.PrimaryPart.Anchored then
  179.                     LocalPlayersCar.PrimaryPart.Anchored = false
  180.                 end
  181.                 if Debounce then
  182.                     Debounce = false
  183.                 end
  184.             end
  185.         else
  186.             if not CarInput.RightShift then
  187.                 CarInput.RightShift = true
  188.             elseif Part.CFrame:ToObjectSpace(LocalPlayersCarPrimaryPart.CFrame).Z < -Part.Size.Z / 2 + Size.Z / 2 then
  189.                 CarPlacer.place(nil, CarTracker.getCarFromDriver(LocalPlayer), Part.CFrame + Vector3.new(0, Part.Size.Y / 2 + Size.Y / 2, Part.Size.Z / 2 - Size.Z / 2))
  190.             end
  191.             local BestInactiveRaceId = GetBestInactiveRaceId()
  192.             if BestInactiveRaceId and BestInactiveRaceId ~= OldBestInactiveRaceId then
  193.                 if not Debounce then
  194.                     Debounce = true
  195.                     OldBestInactiveRaceId = BestInactiveRaceId
  196.                     SignalInterest:FireServer(OldBestInactiveRaceId)
  197.  
  198.                     local Race = assetsraces[OldBestInactiveRaceId]
  199.  
  200.                     local State = Race.State
  201.  
  202.                     local Module = require(Race.Module)
  203.  
  204.                     task.delay(Module.startCountdown, function(...)
  205.                         local NumPlayers = State.NumPlayers
  206.                         if NumPlayers.Value <= Module.minPlayers - 1 then
  207.                             if Debounce then
  208.                                 Debounce = false
  209.                                 return
  210.                             else
  211.                                 return
  212.                             end
  213.                         else
  214.                             return
  215.                         end
  216.                     end)
  217.                 end
  218.             end
  219.         end
  220.         task.wait()
  221.     end
  222. else
  223.     local Hint = Instance.new("Hint")
  224.     Hint.Text = "Please, Spawn/Enter Your Car (Before Executing)!"
  225.     Hint.Name = HttpService:GenerateGUID(true)
  226.     Hint.Parent = CoreGui
  227.     Debris:AddItem(Hint, 5)
  228.     return
  229. end
RAW Paste Data