Advertisement
Sungmingamerpro13

BusTeleportScript (Aquarium Story Style)

Jul 14th, 2024
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 2.89 KB | None | 0 0
  1. local BusTable = {}
  2. local BusPlayers = game.ReplicatedStorage.PlayersInBus
  3. local Dehoune = false
  4. local Teleport = script.Parent
  5. local Seats = Teleport.Bus.Seats
  6. local BusGui = script.Parent.BusPart.BusGui
  7. local BillboardGui = script.Parent.billboardPart.billboardGui
  8. local Teleporting = false
  9. local StartTime = 41
  10. local TeleportID = script.TeleportID.Value
  11. local MinBusPlayers = 1
  12. local MaxBusPlayers = 12
  13. local TeleportService = game:GetService("TeleportService")
  14. local LeaveBus = game.ReplicatedStorage.LeaveBus
  15. local TransitionEvent = game.ReplicatedStorage.TransitionEvent
  16. local EnterBus = game.ReplicatedStorage.EnterBus
  17. local PlayersNumber = game.ReplicatedStorage.PlayersNumber
  18.  
  19. EnterBus.OnServerEvent:Connect(function(Player)
  20.     print('Humanoid')
  21.     local humanoid = Player.Character.Humanoid
  22.     if not table.find(BusTable, Player) and Teleporting == false then
  23.         print('Not found')
  24.         for _, seat in pairs(Seats:GetChildren()) do
  25.             if seat.Occupant == nil then
  26.                 game.ServerStorage.ExitGui:Clone().Parent = Player.PlayerGui
  27.                 seat:Sit(humanoid)
  28.                 humanoid.JumpPower = 0
  29.                 humanoid.WalkSpeed = 0
  30.                 table.insert(BusTable, Player)
  31.                 PlayersNumber.Value -= 1
  32.                 break
  33.             end
  34.         end
  35.     end
  36.  
  37. end)
  38.  
  39. LeaveBus.OnServerEvent:Connect(function(Player)
  40.     local ReturnValue = table.find(BusTable, Player)
  41.     table.remove(BusTable, ReturnValue)
  42.     BusPlayers.Value = #BusTable
  43.     Player:LoadCharacter()
  44.     PlayersNumber.Value += 1
  45. end)
  46.  
  47. PlayersNumber:GetPropertyChangedSignal("Value"):Connect(function()
  48.     BusGui.Frame.Players.Text = "Spaces Left: "..PlayersNumber.Value
  49.     BillboardGui.Frame.Players.Text = "Spaces Left: "..PlayersNumber.Value
  50. end)
  51.  
  52. game.Players.PlayerRemoving:Connect(function(Player)
  53.     if table.find(BusTable, Player) ~= nil then
  54.         local ReturnValue = table.find(BusTable, Player)
  55.         table.remove(BusTable, ReturnValue)
  56.         BusPlayers.Value = #BusTable
  57.         PlayersNumber.Value = #BusTable
  58.     end
  59. end)
  60.  
  61. for i = StartTime, 0, -1 do
  62.     BusGui.Frame.Time.Text = "Time: "..i
  63.     BusGui.Frame.Players.Text = "Spaces Left: "..PlayersNumber.Value
  64.     BillboardGui.Frame.Time.Text = "Time: "..i
  65.     BillboardGui.Frame.Players.Text = "Spaces Left: "..PlayersNumber.Value
  66.     wait(1)
  67.     local Players = #BusTable --see here
  68.     if i == 1 and Players >= MinBusPlayers then
  69.         --Teleport the Players!
  70.  
  71.         game.ReplicatedStorage.Status.Value = "TELEPORTING"
  72.         BusGui.Frame.Status.Text = "TELEPORTING"
  73.         BusGui.Frame.Status.TextColor3 = Color3.fromRGB(255, 0, 0)
  74.         Teleporting = true
  75.         TransitionEvent:FireAllClients()
  76.         wait()
  77.         local Code = TeleportService:ReserveServer(TeleportID)
  78.         TeleportService:TeleportToPrivateServer(TeleportID, Code, BusTable)
  79.         wait(6)
  80.         Teleporting = false
  81.         BusGui.Frame.Status.Text = "READY"
  82.         BusGui.Frame.Status.TextColor3 = Color3.fromRGB(85, 255, 0)
  83.     elseif i == 1 and Players < MinBusPlayers then
  84.  
  85.     elseif Players == MaxBusPlayers then
  86.         --Also teleport the players!
  87.     end
  88. end
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement