Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --!strict
- --Scripted By DeathToTheStadium 03/09/2021 2:44AM PST
- --[[
- _________.__ .__ _________
- / _____/|__| _____ ______ | | ____ \_ ___ \_____ _______
- \_____ \ | |/ \\____ \| | _/ __ \ / \ \/\__ \\_ __ \
- / \| | Y Y \ |_> > |_\ ___/ \ \____/ __ \| | \/
- /_______ /|__|__|_| / __/|____/\___ > \______ (____ /__|
- \/ \/|__| \/ \/ \/
- _________ .__ __
- / _____/ ___________|__|______/ |_
- \_____ \_/ ___\_ __ \ \____ \ __\
- / \ \___| | \/ | |_> > |
- /_______ /\___ >__| |__| __/|__|
- \/ \/ |__|
- ]]
- --Services
- local Debris = game:GetService("Debris")
- local Players = game:GetService("Players")
- --Top Variables
- local Car:Instance = script.Parent.Parent
- local Seat:Instance = Car.VehicleSeat
- local Config:Instance = Car.config
- --PartVaraibles
- local RightWheel:Instance = Car.BW.Part.HingeConstraintRight
- local LeftWheel:Instance = Car.BW.Part.HingeConstraintLeft
- local Axle:Instance = Car.Axle.HingeConstraint
- local Engine:Instance = Config.Engine
- local BillBoard:Instance = Seat.Attachment.BillBoard
- --Settings Variables
- local EngineOn:boolean = false
- function Throttle() -- Handles Speed by using Vehicle Seat
- if Seat.Throttle == 1 then
- Engine:Play()
- if CheckMaxSpeed() then
- Config.Speed.Value += 2
- end
- elseif Seat.Throttle == -1 then
- Engine:Play()
- if CheckMaxSpeed() then
- Config.Speed.Value -= 2
- end
- elseif Seat.Throttle == 0 then
- Engine:Pause()
- Config.Speed.Value =0
- end
- RightWheel.AngularVelocity = -Config.Speed.Value
- LeftWheel.AngularVelocity = Config.Speed.Value
- end
- function Steering(Time)-- Handles Turning by using Vehicle Seat
- if Seat.Steer == 1 then
- Config.TurnSpeed.Value = 25
- elseif Seat.Steer == -1 then
- Config.TurnSpeed.Value = -25
- elseif Seat.Steer == 0 then
- Config.TurnSpeed.Value = 0
- end
- Axle.TargetAngle = Config.TurnSpeed.Value
- end
- function ChildAdded(Child) --Checks For a seat Weld thats been Added by a player sitting Down
- if Child:IsA("Weld") and Child.Name == "SeatWeld" then
- EngineOn = true
- spawn(function()
- while EngineOn do
- wait()
- if Seat.Occupant then
- Throttle()
- Steering()
- else
- EngineOn = false
- end
- end
- end)
- end
- end
- function ChildRemoved(Child) --Checks For a seat Weld thats been Removed by a player Getting up
- if Child:IsA("Weld") and Child.Name == "SeatWeld" then
- Engine:Stop()
- EngineOn = false
- Seat:SetNetworkOwner(nil)
- end
- end
- function CheckMaxSpeed()
- if math.abs(Config.Speed.Value) <= Seat.MaxSpeed then
- return true
- end
- return false
- end
- --Managed Despawning the Car when a Player Leaves
- Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
- if Seat.Occupant == nil then
- --Start Count Down
- BillBoard.Enabled = true
- for i = 60 , 0 ,-1 do
- wait(1)
- BillBoard.Timer.Text = "Despawning In :"..i.."s"
- if (i % 10 == 0) and (i-1 ~= -1) and i ~= 60 then
- BillBoard.Timer.Text = "jump Back in to your Car to Stop the CountDown"
- wait(3)
- end
- if Seat.Occupant then
- BillBoard.Enabled = false
- break
- end
- end
- if BillBoard.Enabled then
- EngineOn = false
- Debris:AddItem(Car,1)
- end
- else
- Seat:SetNetworkOwner(Players:GetPlayerFromCharacter(Seat.Occupant))
- end
- end)
- --Events
- Seat.ChildAdded:Connect(ChildAdded)
- Seat.ChildRemoved:Connect(ChildRemoved)
RAW Paste Data