TheUnknownDiscord

ai car

Oct 15th, 2021 (edited)
94
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local debris = game:GetService("Debris")
  2. Bullet = Instance.new("Part", owner.Character)
  3. Bullet.Position = Vector3.new(1000000,1000000,1000000)
  4. Bullet.Anchored = true
  5. Bullet.CanCollide = false
  6. script.Parent = owner.Character
  7. Seat = Instance.new("VehicleSeat")
  8. Seat.Parent = script
  9. Seat.Size = Vector3.new(4,1,10)
  10. Seat.CFrame = owner.Character.HumanoidRootPart.CFrame * CFrame.new(0,8,-8.057)
  11. Seat.TopSurface = Enum.SurfaceType.Smooth
  12. Seat.BottomSurface = Enum.SurfaceType.Smooth
  13. Bumper = Instance.new("Part")
  14. Bumper.Parent = script
  15. Bumper.Size = Vector3.new(7.75,2.25,1)
  16. Weldlol3 = Instance.new("Weld")
  17. Weldlol3.Parent = Seat
  18. Weldlol3.Part0 = Seat
  19. Weldlol3.Part1 = Bumper
  20. Weldlol3.C1 = Weldlol3.C1 * CFrame.new(0,-1.25,9.75)
  21. side = Instance.new("Part")
  22. side.Parent = script
  23. side.Size = Vector3.new(1.75,0.25,17.15)
  24. Weldside = Instance.new("Weld")
  25. Weldside.Parent = Seat
  26. Weldside.Part0 = Seat
  27. Weldside.Part1 = side
  28. Weldside.C1 = Weldside.C1 * CFrame.new(3.0625,-2.25,0.625)
  29. side2 = Instance.new("Part")
  30. side2.Parent = script
  31. side2.Size = Vector3.new(1.75,0.25,17.15)
  32. Weldside2 = Instance.new("Weld")
  33. Weldside2.Parent = Seat
  34. Weldside2.Part0 = Seat
  35. Weldside2.Part1 = side2
  36. Weldside2.C1 = Weldside2.C1 * CFrame.new(-3.0625,-2.25,0.625)
  37. Bumper3 = Instance.new("Part")
  38. Bumper3.Parent = script
  39. Bumper3.Size = Vector3.new(4,2.25,4.65)
  40. Weldlol32 = Instance.new("Weld")
  41. Weldlol32.Parent = Bumper
  42. Weldlol32.Part0 = Bumper
  43. Weldlol32.Part1 = Bumper3
  44. Weldlol32.C1 = Weldlol32.C1 * CFrame.new(0,0,-2.5)
  45. Bumper2 = Instance.new("Part")
  46. Bumper2.Parent = script
  47. Bumper2.Size = Vector3.new(7.75,2.25,1)
  48. Weldlol31 = Instance.new("Weld")
  49. Weldlol31.Parent = Seat
  50. Weldlol31.Part0 = Seat
  51. Weldlol31.Part1 = Bumper2
  52. Weldlol31.C1 = Weldlol31.C1 * CFrame.new(0,-1.25,-8.5)
  53. Bumper4 = Instance.new("Part")
  54. Bumper4.Parent = script
  55. Bumper4.Size = Vector3.new(4,2.25,4.65)
  56. Weldlol33 = Instance.new("Weld")
  57. Weldlol33.Parent = Bumper2
  58. Weldlol33.Part0 = Bumper2
  59. Weldlol33.Part1 = Bumper4
  60. Weldlol33.C1 = Weldlol33.C1 * CFrame.new(0,0,2.5)
  61. wheel = Instance.new("Part")
  62. wheel.Parent = Seat
  63. wheel.Size = Vector3.new(1,3,3)
  64. steer = Instance.new("Part")
  65. steer.Parent = Seat
  66. steer.Size = Vector3.new(1,1,1)
  67. steer2 = Instance.new("Part")
  68. steer2.Parent = Seat
  69. steer2.Size = Vector3.new(1,1,1)
  70. steer.CFrame = owner.Character.HumanoidRootPart.CFrame * CFrame.new(-3.739,1,-7.25)
  71. steer2.CFrame = owner.Character.HumanoidRootPart.CFrame * CFrame.new(3.739,1,-7.25)
  72. steer.Transparency = 1
  73. steer.CanCollide = false
  74. steer2.Transparency = 1
  75. steer2.CanCollide = false
  76. Seat.Anchored = true
  77. wheel.CFrame = owner.Character.HumanoidRootPart.CFrame * CFrame.new(-3.739,6.5,-7.25)
  78. wheel.TopSurface = Enum.SurfaceType.Smooth
  79. wheel.BottomSurface = Enum.SurfaceType.Smooth
  80. wheel2 = Instance.new("Part")
  81. wheel2.Parent = Seat
  82. wheel2.Size = Vector3.new(1,3,3)
  83. wheel2.CFrame = owner.Character.HumanoidRootPart.CFrame * CFrame.new(3.739,6.5,-7.25)
  84. wheel2.TopSurface = Enum.SurfaceType.Smooth
  85. wheel2.BottomSurface = Enum.SurfaceType.Smooth
  86. wheel3 = Instance.new("Part")
  87. wheel3.Parent = Seat
  88. wheel3.Size = Vector3.new(1,3,3)
  89. wheel3.CFrame = owner.Character.HumanoidRootPart.CFrame * CFrame.new(-3.739,6.5,5.75)
  90. wheel3.TopSurface = Enum.SurfaceType.Smooth
  91. wheel3.BottomSurface = Enum.SurfaceType.Smooth
  92. wheel4 = Instance.new("Part")
  93. wheel4.Parent = Seat
  94. wheel4.Size = Vector3.new(1,3,3)
  95. wheel4.CFrame = owner.Character.HumanoidRootPart.CFrame * CFrame.new(3.739,6.5,5.75)
  96. wheel4.TopSurface = Enum.SurfaceType.Smooth
  97. wheel4.BottomSurface = Enum.SurfaceType.Smooth
  98. wheel.Shape = Enum.PartType.Cylinder
  99. wheel2.Shape = Enum.PartType.Cylinder
  100. wheel3.Shape = Enum.PartType.Cylinder
  101. wheel4.Shape = Enum.PartType.Cylinder
  102. local attachment0 = Instance.new("Attachment")
  103. attachment0.Parent = steer
  104. local attachment1 = Instance.new("Attachment")
  105. attachment1.Parent = Seat
  106. alignposition = Instance.new("HingeConstraint")
  107. alignposition.Parent = Seat
  108. alignposition.ActuatorType = "Servo"
  109. alignposition.TargetAngle = 0
  110. alignposition.Name = "Hinge4"
  111. alignposition.ServoMaxTorque = 10000000
  112. alignposition.AngularSpeed = 10000000
  113. alignposition.Attachment0 = attachment0
  114. alignposition.Attachment1 = attachment1
  115. attachment1.WorldCFrame = attachment1.Parent.CFrame * CFrame.new(-3.739,1,-7.25) * CFrame.Angles(0,math.rad(180),math.rad(90))
  116. local attachment02 = Instance.new("Attachment")
  117. attachment02.Parent = steer2
  118. local attachment12 = Instance.new("Attachment")
  119. attachment12.Parent = Seat
  120. alignposition2 = Instance.new("HingeConstraint")
  121. alignposition2.Parent = Seat
  122. alignposition2.ActuatorType = "Servo"
  123. alignposition2.TargetAngle = 0
  124. alignposition2.Name = "Hinge3"
  125. alignposition2.ServoMaxTorque = 10000000
  126. alignposition2.AngularSpeed = 10000000
  127. alignposition2.Attachment0 = attachment02
  128. alignposition2.Attachment1 = attachment12
  129. attachment12.WorldCFrame = attachment12.Parent.CFrame * CFrame.new(3.739,1,-7.25) * CFrame.Angles(0,0,math.rad(90))
  130. task.wait()
  131. local attachment031 = Instance.new("Attachment")
  132. attachment031.Parent = wheel
  133. local attachment131 = Instance.new("Attachment")
  134. attachment131.Parent = steer
  135. alignposition31 = Instance.new("HingeConstraint")
  136. alignposition31.Parent = Seat
  137. alignposition31.ActuatorType = Enum.ActuatorType.None
  138. alignposition31.Attachment0 = attachment031
  139. alignposition31.Attachment1 = attachment131
  140. attachment131.WorldCFrame = attachment131.Parent.CFrame * CFrame.new(-1,0,0) * CFrame.Angles(0,0,math.rad(-90))
  141. local attachment0231 = Instance.new("Attachment")
  142. attachment0231.Parent = wheel2
  143. local attachment1231 = Instance.new("Attachment")
  144. attachment1231.Parent = steer2
  145. alignposition231 = Instance.new("HingeConstraint")
  146. alignposition231.Parent = Seat
  147. alignposition231.ActuatorType = Enum.ActuatorType.None
  148. alignposition231.Attachment0 = attachment0231
  149. alignposition231.Attachment1 = attachment1231
  150. attachment1231.WorldCFrame = attachment1231.Parent.CFrame * CFrame.new(-1,0,0) * CFrame.Angles(0,0,math.rad(-90))
  151. local attachment03 = Instance.new("Attachment")
  152. attachment03.Parent = wheel3
  153. local attachment13 = Instance.new("Attachment")
  154. attachment13.Parent = Seat
  155. alignposition3 = Instance.new("HingeConstraint")
  156. alignposition3.Parent = Seat
  157. alignposition3.ActuatorType = "Motor"
  158. alignposition3.MotorMaxAcceleration = 10000000
  159. alignposition3.MotorMaxTorque = 10000000
  160. alignposition3.Name = "Hinge1"
  161. alignposition3.Attachment0 = attachment03
  162. alignposition3.Attachment1 = attachment13
  163. attachment13.WorldCFrame = attachment13.Parent.CFrame * CFrame.new(-3.739,0,5.75)* CFrame.Angles(0,math.rad(180),0)
  164. local attachment023 = Instance.new("Attachment")
  165. attachment023.Parent = wheel4
  166. local attachment123 = Instance.new("Attachment")
  167. attachment123.Parent = Seat
  168. alignposition23 = Instance.new("HingeConstraint")
  169. alignposition23.Parent = Seat
  170. alignposition23.ActuatorType = "Motor"
  171. alignposition23.MotorMaxAcceleration = 10000000
  172. alignposition23.MotorMaxTorque = 10000000
  173. alignposition23.Name = "Hinge2"
  174. alignposition23.Attachment0 = attachment023
  175. alignposition23.Attachment1 = attachment123
  176. attachment123.WorldCFrame = attachment123.Parent.CFrame * CFrame.new(3.739,0,5.75)
  177. local motor1 = alignposition3
  178. local motor2 = alignposition23
  179. local steerServo = alignposition
  180. local steerServo2 = alignposition2
  181. local maxSpeed = 20
  182. local angleSteer = 27.5
  183. local density = 1
  184. local friction = 1
  185. local elasticity = 0
  186. local frictionWeight = 100000000000
  187. local elasticityWeight = 0
  188. local physProperties = PhysicalProperties.new(density, friction, elasticity, frictionWeight, elasticityWeight)
  189. Seat.CustomPhysicalProperties = physProperties
  190. wheel.CustomPhysicalProperties = physProperties
  191. wheel2.CustomPhysicalProperties = physProperties
  192. wheel3.CustomPhysicalProperties = physProperties
  193. wheel4.CustomPhysicalProperties = physProperties
  194. wait(0.25)
  195. Seat.Anchored = false
  196. local override = false
  197. local active = false
  198. local stopped = true
  199. owner.Chatted:Connect(function(message)
  200. if message == "!Go" then
  201. active = true
  202. stopped = false
  203. elseif message == "!Stop" then
  204. active = false
  205. stopped = true
  206. alignposition23.AngularVelocity = 0
  207. alignposition3.AngularVelocity = 0
  208. end
  209. end)
  210. local maxSpeed = 20
  211. local angleSteer = 27.5
  212. local function carMove(property)
  213. if not active then
  214. if property == "Throttle" then
  215. alignposition23.AngularVelocity = Seat.Throttle * maxSpeed
  216. alignposition3.AngularVelocity = Seat.Throttle * -maxSpeed
  217. elseif property == "Steer" then
  218. alignposition.TargetAngle = angleSteer * Seat.Steer
  219. alignposition2.TargetAngle = angleSteer * Seat.Steer
  220. end
  221. end
  222. end
  223. Seat.Changed:Connect(carMove)
  224. local bp = Instance.new("BodyPosition",Seat)
  225. bp.D = 100
  226. bp.P = 0
  227. while true do
  228. task.wait()
  229. while active do
  230. task.wait()
  231. if not stopped then
  232. local origin = Bumper.Position
  233. local pos = Bumper.Position * Vector3.new(0,-5,4)
  234. local direction = (pos - origin).Unit*10
  235. local result = game.Workspace:Raycast(origin, direction)
  236. local origin3 = Bumper.Position * Vector3.new(-1,0,0)
  237. local pos3 = Bumper.Position * Vector3.new(-1.25,-5,3.5)
  238. local direction3 = (pos3 - origin3).Unit*10
  239. local result3 = game.Workspace:Raycast(origin3, direction3)
  240. local origin4 = Bumper.Position * Vector3.new(1,0,0)
  241. local pos4 = Bumper.Position * Vector3.new(1.25,-5,3.5)
  242. local direction4 = (pos4 - origin4).Unit*10
  243. local result4 = game.Workspace:Raycast(origin4, direction4)
  244. if result == nil and result3 == nil and result4 == nil then
  245. active = false
  246. bp.P = 10000
  247. bp.position = Seat.Position
  248. wait(0.75)
  249. bp.P = 0
  250. alignposition23.AngularVelocity = -1 * maxSpeed
  251. alignposition3.AngularVelocity = -1 * -maxSpeed
  252. alignposition.TargetAngle = angleSteer * 1
  253. alignposition2.TargetAngle = angleSteer * 1
  254. override = true
  255. wait(2.5)
  256. alignposition23.AngularVelocity = 1 * maxSpeed
  257. alignposition3.AngularVelocity = 1 * -maxSpeed
  258. alignposition.TargetAngle = angleSteer * -1
  259. alignposition2.TargetAngle = angleSteer * -1
  260. wait(2.5)
  261. alignposition23.AngularVelocity = 0 * maxSpeed
  262. alignposition3.AngularVelocity = 0 * -maxSpeed
  263. alignposition.TargetAngle = angleSteer * 0
  264. alignposition2.TargetAngle = angleSteer * 0
  265. active = true
  266. override = false
  267. elseif result4 == nil then
  268. alignposition.TargetAngle = angleSteer * 1
  269. alignposition2.TargetAngle = angleSteer * 1
  270. alignposition23.AngularVelocity = 1 * maxSpeed
  271. alignposition3.AngularVelocity = 1 * -maxSpeed
  272. active = false
  273. override = true
  274. wait(1.5)
  275. alignposition.TargetAngle = angleSteer * 0
  276. alignposition2.TargetAngle = angleSteer * 0
  277. alignposition23.AngularVelocity = 0 * maxSpeed
  278. alignposition3.AngularVelocity = 0 * -maxSpeed
  279. active = true
  280. override = false
  281. elseif result == nil then
  282. alignposition.TargetAngle = angleSteer * 1
  283. alignposition2.TargetAngle = angleSteer * 1
  284. alignposition23.AngularVelocity = 1 * maxSpeed
  285. alignposition3.AngularVelocity = 1 * -maxSpeed
  286. active = false
  287. override = true
  288. wait(1.5)
  289. alignposition.TargetAngle = angleSteer * 0
  290. alignposition2.TargetAngle = angleSteer * 0
  291. alignposition23.AngularVelocity = 0 * maxSpeed
  292. alignposition3.AngularVelocity = 0 * -maxSpeed
  293. active = true
  294. override = false
  295. elseif result3 == nil then
  296. alignposition.TargetAngle = angleSteer * -1
  297. alignposition2.TargetAngle = angleSteer * -1
  298. alignposition23.AngularVelocity = 1 * maxSpeed
  299. alignposition3.AngularVelocity = 1 * -maxSpeed
  300. override = true
  301. active = false
  302. wait(1.5)
  303. alignposition.TargetAngle = angleSteer * 0
  304. alignposition2.TargetAngle = angleSteer * 0
  305. alignposition23.AngularVelocity = 0 * maxSpeed
  306. alignposition3.AngularVelocity = 0 * -maxSpeed
  307. active = true
  308. override = false
  309. end
  310. else
  311. end
  312. random1 = math.random(-1, 2)
  313. random2 = math.random(0.1, 2)
  314. random3 = math.random(0.1, 2)
  315. alignposition23.AngularVelocity = 1 * maxSpeed
  316. alignposition3.AngularVelocity = 1 * -maxSpeed
  317. alignposition.TargetAngle = angleSteer * random1
  318. alignposition2.TargetAngle = angleSteer * random1
  319. wait(random2)
  320. alignposition23.AngularVelocity = 1 * maxSpeed
  321. alignposition3.AngularVelocity = 1 * -maxSpeed
  322. alignposition.TargetAngle = 0
  323. alignposition2.TargetAngle = 0
  324. wait(random3)
  325. end
  326. end
RAW Paste Data