1. -- services
  2. local players = game:GetService("Players")
  3. local rs = game:GetService("ReplicatedStorage")
  4. local runs = game:GetService("RunService")
  5. -- variables
  6. local lp = players.LocalPlayer
  7. local vehicleInfo = rs:WaitForChild("VehicleInformation")
  8. local carCollection = workspace.CarCollection
  9. local rfSpawnVehicle = rs:WaitForChild("rF").SpawnVehicle
  10. local lavaPart = workspace.Crushers["Volcano Pit"].Scripted.Lava
  11. local sp = workspace.Lobby.SpawnPoints.Spawn1
  12. local guiScript = getsenv(lp.PlayerGui:WaitForChild("GUIs"))
  13. local openFunc = guiScript["OpenDealership"]
  14. local spawnFunc = guiScript["SpawnButton"]
  15. -- functions
  16. local function getCurrentCar()
  17. local car = carCollection:FindFirstChild(lp.Name)
  18. if not car then return nil end
  19. local model = car:FindFirstChild("Car")
  20. if not model then return nil end
  21. local isNotBroken =
  22. model:FindFirstChild("Wheels"):FindFirstChildOfClass("Part") and
  23. model:FindFirstChild("Body"):FindFirstChild("Engine"):FindFirstChildOfClass("MeshPart")
  24. return isNotBroken and model or nil
  25. end
  26. local function getCharacter()
  27. return lp.Character or lp.CHaracterAdded:Wait()
  28. end
  29. local function getMoney()
  30. return lp.Money.Value
  31. end
  32. local function canSpawn()
  33. return lp.SpawnTimer.Value <= 0
  34. end
  35. local function spawnBestCar()
  36. openFunc()
  37. spawnFunc(true, Enum.UserInputState.Begin)
  38. end
  39. local function destroyCar()
  40. local hum = getCharacter():FindFirstChildOfClass("Humanoid")
  41. local hrp = getCharacter():FindFirstChild("HumanoidRootPart")
  42. if not hum or not hrp then return end
  43. local car = getCurrentCar()
  44. repeat task.wait() until car.PrimaryPart ~= nil
  45. -- Death to the car!!!
  46. repeat task.wait()
  47. car = getCurrentCar()
  48. if not car then return end
  49. car.PrimaryPart.Velocity = Vector3.new(0, 250, 0)
  50. car.PrimaryPart.CFrame *= CFrame.Angles(180, 0, 0)
  51. task.wait(.25)
  52. car.PrimaryPart.Velocity = Vector3.new(0, -250, 0)
  53. car.PrimaryPart.CFrame *= CFrame.Angles(180, 0, 0)
  54. task.wait(.25)
  55. until not car
  56. end
  57. -- main
  58. while task.wait() do
  59. local character = getCharacter()
  60. if not character then return end
  61. if canSpawn() then
  62. spawnBestCar()
  63. destroyCar()
  64. end
  65. end