Advertisement
Sungmingamerpro13

Bus MainScript 2

Jan 7th, 2023 (edited)
1,242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 4.22 KB | None | 0 0
  1. local TS = game:GetService("TeleportService")
  2. local TweenService = game:GetService("TweenService")
  3. local placeId = (0)
  4. local leaveGuiEvent = game.ReplicatedStorage.LeaveGuiEvent
  5. local TransitionEvent = game.ReplicatedStorage.TransitionEvent
  6. local list = {}
  7. local billboard = script.Parent.billboardPart.billboardGui
  8. local timer
  9. local teleporting = false
  10. local spawnTeleport = script.Parent.spawn
  11. local MinPlayers = 1
  12. local MaxPlayers = 12
  13. local GuiPart = script.Parent.GuiPart
  14. local Debounce = false
  15. local Seats = script.Parent.Parent.Bus.Seats:GetChildren()
  16.  
  17. local function updateGui()
  18.     billboard.Frame.players.Text = "Players: " ..#list.. "/12"
  19.     GuiPart.SurfaceGui.Frame.players.Text = "Players: "..#list.."/12"
  20. end
  21.  
  22. local function removeFromList(character)
  23.     for i=1,#list do
  24.         if list[i] == character.Name then
  25.             table.remove(list,i)
  26.             updateGui()
  27.         end
  28.     end
  29. end
  30.  
  31. local function teleportPlayers()
  32.     if #list >= MinPlayers then
  33.         billboard.Frame.Status.Text = "TELEPORTING"
  34.         billboard.Frame.Status.TextColor3 = Color3.fromRGB(255, 0, 0)
  35.         GuiPart.SurfaceGui.Frame.Status.Text = "TELEPORTING"
  36.         GuiPart.SurfaceGui.Frame.Status.TextColor3 = Color3.fromRGB(255, 0, 0)
  37.         local playersToTeleport = {}
  38.         local teleportTime = 0
  39.         for i=1,#list do
  40.             if game.Players:findFirstChild(list[i]) then
  41.                 table.insert(playersToTeleport,game.Players:findFirstChild(list[i]))
  42.                 TransitionEvent:FireClient(game.Players:findFirstChild(list[i]))
  43.             else
  44.                 table.remove(list,i)   
  45.             end
  46.         end
  47.         local code = TS:ReserveServer(placeId)
  48.         teleporting = true
  49.         TS:TeleportToPrivateServer(placeId,code,playersToTeleport)
  50.         repeat wait() until #list <= 0
  51.         billboard.Frame.Status.Text = "START"
  52.         billboard.Frame.Status.TextColor3 = Color3.fromRGB(85, 255, 0)
  53.         GuiPart.SurfaceGui.Frame.Status.Text = "START"
  54.         GuiPart.SurfaceGui.Frame.Status.TextColor3 = Color3.fromRGB(85, 255, 0)
  55.         teleporting = false
  56.     elseif #list < MinPlayers then
  57.         GuiPart.SurfaceGui.Frame.players.Text = MinPlayers.." Players Needed!"
  58.         billboard.Frame.players.Text = MinPlayers.." Players Needed!"
  59.         wait(1)
  60.         billboard.Frame.players.Text = "Players: "..#list.."/12"
  61.         GuiPart.SurfaceGui.Frame.players.Text = "Players: "..#list.."/12"
  62.     end
  63. end
  64.  
  65. script.Parent.BusEnter.Touched:Connect(function(hit)
  66.     if hit.Parent:findFirstChild("Humanoid") then
  67.         if teleporting == false then
  68.             local char = hit.Parent
  69.             local player = game.Players:FindFirstChild(char.Name)
  70.             local alreadyExists = false
  71.  
  72.             for i=1,#list do
  73.                 if list[i] == char.Name then
  74.                     alreadyExists = true
  75.                 end
  76.             end
  77.  
  78.             if alreadyExists == false then
  79.                 if #list < MaxPlayers then -- Many Players have been teleported.
  80.                     table.insert(list,char.Name)
  81.                     char.PrimaryPart.CFrame = spawnTeleport.CFrame
  82.                     if Debounce then return end
  83.                     local player = game.Players:GetPlayerFromCharacter(hit.Parent)
  84.                     for i, v in pairs(Seats) do
  85.                         if Seats.Occupant == nil then
  86.                             local Check = Instance.new("Weld")
  87.                             Check.Name = "Check"
  88.                             Check.Parent = player.Character
  89.                             Check.Parent.Humanoid.JumpPower = 0
  90.                             Check.Parent.Humanoid.WalkSpeed = 0
  91.                         end
  92.                     end
  93.                     Seats[math.random(1, #Seats)]:Sit(player.Character.Humanoid)
  94.                     updateGui()
  95.                     game.ServerStorage.ExitGui:Clone().Parent = player.PlayerGui
  96.                 end
  97.                 player.CharacterRemoving:connect(function(character)
  98.                     removeFromList(character)
  99.                 end)
  100.             end
  101.  
  102.         end
  103.     end
  104. end)
  105.  
  106. leaveGuiEvent.OnServerEvent:Connect(function(player)
  107.     player:LoadCharacter()
  108. end)
  109.  
  110. while wait() do
  111.     timer = 41
  112.     for i=1,timer do
  113.         timer = timer - 1
  114.         billboard.Frame.time.Text = timer
  115.         GuiPart.SurfaceGui.Frame.time.Text = timer
  116.         wait(1)
  117.     end
  118.     teleportPlayers()
  119. end
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement