DeathToTheStadium

a Simple Car Script

Mar 9th, 2021
586
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --!strict
  2.  
  3. --Scripted By DeathToTheStadium 03/09/2021 2:44AM PST
  4.  
  5.  
  6. --[[
  7.  
  8.   _________.__               .__           _________              
  9.  /   _____/|__| _____ ______ |  |   ____   \_   ___ \_____ _______
  10.  \_____  \ |  |/     \\____ \|  | _/ __ \  /    \  \/\__  \\_  __ \
  11.  /        \|  |  Y Y  \  |_> >  |_\  ___/  \     \____/ __ \|  | \/
  12. /_______  /|__|__|_|  /   __/|____/\___  >  \______  (____  /__|  
  13.         \/          \/|__|             \/          \/     \/      
  14.               _________            .__        __                  
  15.              /   _____/ ___________|__|______/  |_                
  16.              \_____  \_/ ___\_  __ \  \____ \   __\                
  17.              /        \  \___|  | \/  |  |_> >  |                  
  18.             /_______  /\___  >__|  |__|   __/|__|                  
  19.                     \/     \/         |__|                        
  20.  
  21. ]]
  22.  
  23.  
  24.  
  25. --Services
  26.  
  27. local Debris  = game:GetService("Debris")
  28. local Players = game:GetService("Players")
  29.  
  30. --Top Variables
  31. local Car:Instance         = script.Parent.Parent
  32. local Seat:Instance        = Car.VehicleSeat
  33. local Config:Instance      = Car.config
  34.  
  35. --PartVaraibles
  36. local RightWheel:Instance = Car.BW.Part.HingeConstraintRight
  37. local LeftWheel:Instance   = Car.BW.Part.HingeConstraintLeft
  38. local Axle:Instance        = Car.Axle.HingeConstraint
  39. local Engine:Instance      = Config.Engine
  40. local BillBoard:Instance   = Seat.Attachment.BillBoard
  41.  
  42. --Settings Variables
  43. local EngineOn:boolean   = false
  44.  
  45.  
  46. function Throttle() -- Handles Speed by using  Vehicle Seat
  47.     if Seat.Throttle     == 1  then
  48.         Engine:Play()
  49.         if CheckMaxSpeed() then
  50.             Config.Speed.Value += 2
  51.         end
  52.     elseif Seat.Throttle == -1 then
  53.         Engine:Play()
  54.         if CheckMaxSpeed() then
  55.             Config.Speed.Value -= 2
  56.         end
  57.     elseif Seat.Throttle == 0  then
  58.         Engine:Pause()
  59.         Config.Speed.Value =0
  60.     end
  61.     RightWheel.AngularVelocity = -Config.Speed.Value
  62.     LeftWheel.AngularVelocity  = Config.Speed.Value
  63. end
  64.  
  65. function Steering(Time)-- Handles Turning by using Vehicle Seat
  66.     if Seat.Steer      == 1  then
  67.         Config.TurnSpeed.Value = 25
  68.     elseif Seat.Steer  == -1 then
  69.         Config.TurnSpeed.Value = -25
  70.     elseif Seat.Steer  == 0  then
  71.         Config.TurnSpeed.Value = 0
  72.     end
  73.     Axle.TargetAngle = Config.TurnSpeed.Value
  74. end
  75.  
  76.  
  77. function ChildAdded(Child) --Checks For a seat Weld thats been Added by a player sitting Down
  78.     if Child:IsA("Weld") and Child.Name == "SeatWeld" then
  79.         EngineOn = true
  80.         spawn(function()
  81.             while EngineOn do
  82.                 wait()
  83.                 if Seat.Occupant then
  84.                     Throttle()
  85.                     Steering()
  86.                 else
  87.                     EngineOn = false
  88.                 end
  89.             end
  90.         end)
  91.     end
  92. end
  93.  
  94. function ChildRemoved(Child) --Checks For a seat Weld thats been Removed by a player Getting up
  95.     if Child:IsA("Weld") and Child.Name == "SeatWeld" then
  96.         Engine:Stop()
  97.         EngineOn = false
  98.         Seat:SetNetworkOwner(nil)
  99.     end
  100. end
  101.  
  102.  
  103. function CheckMaxSpeed()
  104.     if math.abs(Config.Speed.Value) <= Seat.MaxSpeed then
  105.         return true
  106.     end
  107.     return false
  108. end
  109.  
  110. --Managed Despawning the Car when a Player Leaves
  111. Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
  112.     if Seat.Occupant == nil then
  113.         --Start Count Down
  114.         BillBoard.Enabled = true
  115.         for i = 60 , 0 ,-1 do
  116.             wait(1)
  117.             BillBoard.Timer.Text = "Despawning In :"..i.."s"
  118.             if (i % 10 == 0) and (i-1 ~= -1) and i ~= 60 then
  119.                 BillBoard.Timer.Text = "jump Back in to your Car to Stop the CountDown"
  120.                 wait(3)
  121.             end
  122.             if Seat.Occupant then
  123.                 BillBoard.Enabled = false
  124.                 break
  125.             end
  126.         end
  127.         if BillBoard.Enabled then
  128.             EngineOn = false
  129.             Debris:AddItem(Car,1)
  130.         end
  131.     else
  132.         Seat:SetNetworkOwner(Players:GetPlayerFromCharacter(Seat.Occupant))
  133.     end
  134. end)
  135.  
  136.  
  137. --Events
  138. Seat.ChildAdded:Connect(ChildAdded)
  139.  
  140. Seat.ChildRemoved:Connect(ChildRemoved)
  141.  
  142.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×