UsernameRTX

Driving Simulator Auto-farm

Dec 4th, 2021 (edited)
7,418
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local Debris = game:GetService("Debris")
  2.  
  3. local renv = getrenv()
  4. local Realshared = renv.shared
  5.  
  6. local raceColliders = workspace["$raceColliders"]
  7. local Placeables = workspace["%Placeables"]
  8.  
  9. local player = Realshared.player
  10.  
  11. local races = Realshared.asset("/races")
  12.  
  13. local Go = Realshared.remote("/races/Go")
  14. local SignalInterest = Realshared.remote("/races/SignalInterest")
  15. local StartRace = Realshared.remote("/races/StartRace")
  16.  
  17. local CarTracker = select(2, pcall(Realshared.import, "/pcar/CarTracker"))
  18. local ClientCarState = select(2, pcall(Realshared.import, "/pcar/ClientCarState"))
  19.  
  20. local ClientRaceState = select(2, pcall(Realshared.import, "/prace/ClientRaceState.client"))
  21.  
  22. local BindableEvent = Instance.new("BindableEvent")
  23.  
  24. local function PlaceablesChildAdded(Child)
  25.     if Child.Name == "Checkpoint" then
  26.         local RootPart = Child.RootPart
  27.  
  28.         local FormerPosition = RootPart.Position
  29.         repeat
  30.             if Child.Parent and RootPart.Position ~= FormerPosition then
  31.                 BindableEvent:Fire()
  32.             end
  33.             FormerPosition = RootPart.Position
  34.             task.wait(.1)
  35.         until not Child.Parent
  36.         return
  37.     else
  38.         return
  39.     end
  40.     return
  41. end
  42.  
  43. local function PlaceablesChildRemoved()
  44.     BindableEvent:Fire()
  45.     return
  46. end
  47.  
  48. local function IsraceColliderLoaded(raceId, raceColliderId)
  49.     return raceColliders[raceId]:FindFirstChild(tostring(raceColliderId)) and true or false
  50. end
  51.  
  52. local function LoadraceCollider(raceId, raceColliderId)
  53.     local CarFromDriver = CarTracker.getCarFromDriver(player)
  54.  
  55.     local RootPart = CarFromDriver.RootPart
  56.  
  57.     if not RootPart.Anchored then
  58.         RootPart.Anchored = true
  59.     end
  60.     CarFromDriver:SetPrimaryPartCFrame(races[raceId].Checkpoints[tostring(raceColliderId)].ArrowRefCFrame.Value)
  61.     raceColliders[raceId]:WaitForChild(tostring(raceColliderId))
  62.     if RootPart.Anchored then
  63.         RootPart.Anchored = false
  64.     end
  65.     return
  66. end
  67.  
  68. local function HitraceCollider(raceId, raceColliderId)
  69.     CarTracker.getCarFromDriver(player):SetPrimaryPartCFrame(raceColliders[raceId][tostring(raceColliderId)].CFrame)
  70.     return
  71. end
  72.  
  73. local Blacklist = {
  74.     "CreateRace",
  75.     "RaceNotifier",
  76.     "ServerAlert"
  77. }
  78. local OldNameCall = nil
  79. local function hookmetamethodFunction(Self, ...)
  80.     if table.find(Blacklist, Self.Name) then
  81.         return
  82.     end
  83.     return OldNameCall(Self, ...)
  84. end
  85.  
  86. local function StartRaceOnClientEvent(raceId)
  87.     Go.OnClientEvent:Wait()
  88.     for Count1 = 1, require(races[raceId].Module).laps do
  89.         for Count2 = 1, raceColliders:WaitForChild(raceId).NumCheckpoints.Value do
  90.             if not ClientRaceState.racing then
  91.                 break
  92.             end
  93.             if not IsraceColliderLoaded(raceId, Count2) then
  94.                 LoadraceCollider(raceId, Count2)
  95.             end
  96.             HitraceCollider(raceId, Count2)
  97.             BindableEvent.Event:Wait()
  98.         end
  99.     end
  100.     return
  101. end
  102.  
  103. local function GetraceQuality(race)
  104.     local State = race.State
  105.  
  106.     return State.NumPlayers.Value / State.TimeUntilStart.Value * require(race.Module).startCountdown
  107. end
  108.  
  109. local function GetHighestQualityrace()
  110.     local HighestraceQuality = -math.huge
  111.     local HighestQualityrace = nil
  112.     local function foreachi(_, Value)
  113.         local State = Value.State
  114.  
  115.         local NumPlayers = State.NumPlayers
  116.  
  117.         if NumPlayers.Value < table.getn(Value.Places:GetChildren()) and NumPlayers.Value > 0 and not State.RaceActive.Value then
  118.             local raceQuality = GetraceQuality(Value)
  119.             if raceQuality > HighestraceQuality then
  120.                 HighestraceQuality = raceQuality
  121.                 HighestQualityrace = Value
  122.             end
  123.             return
  124.         else
  125.             return
  126.         end
  127.         return
  128.     end
  129.     table.foreachi(races:GetChildren(), foreachi)
  130.     if HighestQualityrace then
  131.         print(HighestQualityrace, HighestQualityrace.State.TimeUntilStart.Value * require(HighestQualityrace.Module).startCountdown)
  132.     end
  133.     return HighestQualityrace
  134. end
  135.  
  136. local HighestQualityrace = nil
  137. local FormerHighestQualityrace = nil
  138. local EndValue = 2500
  139. local Reverse = false
  140. local Speed = 100
  141. local function Update()
  142.     if ClientCarState.isDriving and not ClientRaceState.racing then
  143.         for Count = 1, EndValue, 6 do
  144.             if not ClientCarState.isDriving or ClientRaceState.racing then
  145.                 break
  146.             end
  147.             if HighestQualityrace then
  148.                 if HighestQualityrace.State.TimeUntilStart.Value * require(HighestQualityrace.Module).startCountdown <= 1 then
  149.                     SignalInterest:FireServer(HighestQualityrace.Name)
  150.                 end
  151.                 if HighestQualityrace ~= FormerHighestQualityrace then
  152.                     FormerHighestQualityrace = HighestQualityrace
  153.                 end
  154.             end
  155.             HighestQualityrace = GetHighestQualityrace()
  156.             CarTracker.getCarFromDriver(player):SetPrimaryPartCFrame(CFrame.new(0, 0, not Reverse and Count or Reverse and EndValue - Count))
  157.             task.wait(1 / Speed)
  158.         end
  159.         Reverse = not Reverse
  160.         return
  161.     else
  162.         return
  163.     end
  164.     return
  165. end
  166.  
  167. local function Initialize()
  168.     if not ClientCarState.isDriving then
  169.         local Hint = Instance.new("Hint")
  170.         Hint.Text = "Please, Spawn/Enter Your Car (Before Executing)!"
  171.         Hint.Parent = workspace
  172.         Debris:AddItem(Hint, 5)
  173.         return
  174.     end
  175.     Placeables.ChildAdded:Connect(PlaceablesChildAdded)
  176.     Placeables.ChildRemoved:Connect(PlaceablesChildRemoved)
  177.     OldNameCall = hookmetamethod(game, "__namecall", hookmetamethodFunction)
  178.     StartRace.OnClientEvent:Connect(StartRaceOnClientEvent)
  179.     workspace.Gravity = 0
  180.     while true do
  181.         Update()
  182.         task.wait(.1)
  183.     end
  184.     return
  185. end
  186. Initialize()
RAW Paste Data