Advertisement
Sungmingamerpro13

Bus MainScript 3

Jan 7th, 2023
1,349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 3.56 KB | None | 0 0
  1. local TransitionEvent = game.ReplicatedStorage.TransitionEvent
  2. local TeleportService = game:GetService("TeleportService")
  3. local TeleportID = 11156840762 -- Change to your game ID
  4.  
  5. local Players = {}
  6. local IsTeleporting = false
  7. local TeleportPoint = script.Parent.TeleportPoint
  8. local PlayersAllowed = script.Parent.PlayersAllowed
  9.  
  10. local Gate = script.Parent.Gate
  11. local Timer
  12.  
  13. local Frame = Gate.SurfaceGui:WaitForChild("Frame")
  14. local PlayerNumber = Frame:WaitForChild("PlayerNumber")
  15. local TimeNumber = Frame:WaitForChild("TimeNumber")
  16. local ExitEvent = game.ReplicatedStorage.ExitEvent
  17.  
  18. local Truck = script.Parent.Parent.Truck
  19. local Seats = Truck:GetChildren()
  20. local Debounce = false
  21.  
  22. local teleporting = false
  23. local MaxPlayers = 12
  24.  
  25. game.Players.RespawnTime = 0
  26.  
  27. function Refresh()
  28.     PlayerNumber.Text = #Players
  29. end
  30.  
  31. local function RemoveFromList(Char)
  32.     for i = 1,#Players do
  33.         if Players[i] == Char.Name then
  34.             table.remove(Players, i)
  35.             Char.Humanoid.JumpPower = 50
  36.             Refresh()
  37.         end
  38.     end
  39. end
  40.  
  41.  
  42. local function Teleport()
  43.     if #Players > 0 then
  44.         local TeleportPlayers = {}
  45.  
  46.         for i = 1, #Players do
  47.             if game.Players:FindFirstChild(Players[i]) then
  48.                 table.insert(TeleportPlayers, game.Players:FindFirstChild(Players[i]))
  49.                 TransitionEvent:FireClient(game.Players:FindFirstChild(Players[i]))
  50.             else
  51.                 table.remove(Players, i)
  52.             end
  53.         end
  54.  
  55.         local Code = TeleportService:Teleport(TeleportID)
  56.        
  57.         IsTeleporting = true
  58.         --TeleportService:TeleportToPrivateServer(TeleportID, Code, TeleportPlayers)
  59.        
  60.         repeat wait() until #Players <= 0
  61.        
  62.         IsTeleporting = false
  63.     end
  64. end
  65.  
  66.  
  67. Gate.Touched:Connect(function(hit)
  68.     if hit.Parent:findFirstChild("Humanoid") then
  69.         if teleporting == false then
  70.             local char = hit.Parent
  71.             local player = game.Players:FindFirstChild(char.Name)
  72.             local alreadyExists = false
  73.  
  74.             for i=1,#Players do
  75.                 if Players[i] == char.Name then
  76.                     alreadyExists = true
  77.                 end
  78.             end
  79.  
  80.             if alreadyExists == false then
  81.                 if #Players < MaxPlayers then -- Many Players have been teleported.
  82.                     table.insert(Players,char.Name)
  83.                     char.PrimaryPart.CFrame = TeleportPoint.CFrame
  84.                     if Debounce then return end
  85.                     local player = game.Players:GetPlayerFromCharacter(hit.Parent)
  86.                     for i, v in pairs(Seats) do
  87.                         if Seats.Occupant == nil then
  88.                             local Check = Instance.new("Weld")
  89.                             Check.Name = "Check"
  90.                             Check.Parent = player.Character
  91.                             Check.Parent.Humanoid.JumpPower = 0
  92.                             Check.Parent.Humanoid.WalkSpeed = 0
  93.                         end
  94.                     end
  95.                     Seats[math.random(1, #Seats)]:Sit(player.Character.Humanoid)
  96.                     Refresh()
  97.                     game.ServerStorage.ExitGui:Clone().Parent = player.PlayerGui
  98.                 end
  99.                 player.CharacterRemoving:connect(function(character)
  100.                     RemoveFromList(character)
  101.                 end)
  102.             end
  103.  
  104.         end
  105.     end
  106. end)
  107.  
  108. ExitEvent.OnServerEvent:Connect(function(player)
  109.     if player.Character then
  110.         player:LoadCharacter()
  111.         RemoveFromList(player.Character)
  112.     end
  113. end)
  114.  
  115. while wait() do
  116.     Timer = 20
  117.    
  118.     for i = 1, Timer do
  119.         Timer = Timer - 1
  120.         TimeNumber.Text = Timer
  121.         wait(1)
  122.     end
  123.     Teleport()
  124. end
  125.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement