Urbanpower

Car Crushers 2: Auto Farm

Mar 20th, 2023
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. -- services
  2. local players = game:GetService("Players")
  3. local rs = game:GetService("ReplicatedStorage")
  4. local runs = game:GetService("RunService")
  5.  
  6. -- variables
  7. local lp = players.LocalPlayer
  8. local vehicleInfo = rs:WaitForChild("VehicleInformation")
  9. local carCollection = workspace.CarCollection
  10. local rfSpawnVehicle = rs:WaitForChild("rF").SpawnVehicle
  11. local lavaPart = workspace.Crushers["Volcano Pit"].Scripted.Lava
  12. local sp = workspace.Lobby.SpawnPoints.Spawn1
  13. local guiScript = getsenv(lp.PlayerGui:WaitForChild("GUIs"))
  14. local openFunc = guiScript["OpenDealership"]
  15. local spawnFunc = guiScript["SpawnButton"]
  16.  
  17. -- functions
  18. local function getCurrentCar()
  19. local car = carCollection:FindFirstChild(lp.Name)
  20. if not car then return nil end
  21.  
  22. local model = car:FindFirstChild("Car")
  23. if not model then return nil end
  24.  
  25. local isNotBroken =
  26. model:FindFirstChild("Wheels"):FindFirstChildOfClass("Part") and
  27. model:FindFirstChild("Body"):FindFirstChild("Engine"):FindFirstChildOfClass("MeshPart")
  28.  
  29. return isNotBroken and model or nil
  30. end
  31.  
  32. local function getCharacter()
  33. return lp.Character or lp.CHaracterAdded:Wait()
  34. end
  35.  
  36. local function getMoney()
  37. return lp.Money.Value
  38. end
  39.  
  40. local function canSpawn()
  41. return lp.SpawnTimer.Value <= 0
  42. end
  43.  
  44. local function spawnBestCar()
  45. openFunc()
  46. spawnFunc(true, Enum.UserInputState.Begin)
  47. end
  48.  
  49. local function destroyCar()
  50. local hum = getCharacter():FindFirstChildOfClass("Humanoid")
  51. local hrp = getCharacter():FindFirstChild("HumanoidRootPart")
  52.  
  53. if not hum or not hrp then return end
  54.  
  55. local car = getCurrentCar()
  56.  
  57. repeat task.wait() until car.PrimaryPart ~= nil
  58.  
  59. -- Death to the car!!!
  60. repeat task.wait()
  61. car = getCurrentCar()
  62. if not car then return end
  63.  
  64. car.PrimaryPart.Velocity = Vector3.new(0, 250, 0)
  65. car.PrimaryPart.CFrame *= CFrame.Angles(180, 0, 0)
  66.  
  67. task.wait(.25)
  68.  
  69. car.PrimaryPart.Velocity = Vector3.new(0, -250, 0)
  70. car.PrimaryPart.CFrame *= CFrame.Angles(180, 0, 0)
  71.  
  72. task.wait(.25)
  73. until not car
  74. end
  75.  
  76. -- main
  77. while task.wait() do
  78. local character = getCharacter()
  79.  
  80. if not character then return end
  81.  
  82. if canSpawn() then
  83. spawnBestCar()
  84. destroyCar()
  85. end
  86. end
Add Comment
Please, Sign In to add comment