Advertisement
Sungmingamerpro13

Bus MainScript (Bus TeleportScript)

May 8th, 2024
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 2.74 KB | None | 0 0
  1. local TS = game:GetService("TeleportService")
  2. local GuiPart = script.Parent.Parent.GuiPart
  3. local Seats = script.Parent.Parent.BusModel.SeatsModel:GetChildren()
  4.  
  5. local List = {}
  6. local MinPlayers = 1
  7. local MaxPlayers = 12
  8. local Timer
  9.  
  10. local PlaceId = (17424851138)
  11.  
  12. GuiPart.SurfaceGui.Players.Text = "Players: "..#List.." / "..MaxPlayers
  13.  
  14. local function removeFromList(character)
  15.     for i=1,#List do
  16.         if List[i] == character.Name then
  17.             table.remove(List,i)
  18.             GuiPart.SurfaceGui.Players.Text = "Players: "..#List.." / "..MaxPlayers
  19.         end
  20.     end
  21. end
  22.  
  23. local function TeleportPlayers()
  24.     if #List >= MinPlayers then
  25.         GuiPart.SurfaceGui.Status.Text = "Teleporting..."
  26.         GuiPart.SurfaceGui.Status.TextColor3 = Color3.new(1, 0, 0)
  27.         local playersToTeleport = {}
  28.         for i=1,#List do
  29.             if game.Players:FindFirstChild(List[i]) then
  30.                 table.insert(playersToTeleport, game.Players:FindFirstChild(List[i]))
  31.                 game.ReplicatedStorage.TransitionEvent:FireClient(game.Players:FindFirstChild(List[i]))
  32.             else
  33.                 table.remove(List,i)
  34.             end
  35.         end
  36.         local Code = TS:ReserveServer(PlaceId)
  37.         TS:TeleportToPrivateServer(PlaceId, Code, playersToTeleport)
  38.         repeat wait() until #List <= 0
  39.         GuiPart.SurfaceGui.Status.Text = "READY"
  40.         GuiPart.SurfaceGui.Status.TextColor3 = Color3.new(0.333333, 1, 0)
  41.     else
  42.         GuiPart.SurfaceGui.Players.Text = "1 Players Neeeded"
  43.         wait(2.5)
  44.         GuiPart.SurfaceGui.Players.Text = "Players: "..#List.." / "..MaxPlayers
  45.     end
  46. end
  47.  
  48. script.Parent.Touched:Connect(function(Hit)
  49.     if Hit.Parent:FindFirstChild("Humanoid") then
  50.        
  51.         local character = Hit.Parent
  52.         local Player = game.Players:GetPlayerFromCharacter(character)
  53.         local alreadyExists = false
  54.        
  55.         for i=1,#List do
  56.             if List[i] == character.Name then
  57.                 alreadyExists = true
  58.             end
  59.         end
  60.        
  61.         if alreadyExists == false then
  62.             if #List < MinPlayers then
  63.                 table.insert(List,character.Name)
  64.                 for i, v in pairs(Seats) do
  65.                     if Seats == nil then
  66.                         local Check = Instance.new("Weld")
  67.                         Check.Name = "Check"
  68.                         Check.Parent = Player.Character
  69.                         Check.Parent.Humanoid.JumpPower = 0
  70.                         Check.Parent.Humanoid.WalkSpeed = 0
  71.                     end
  72.                 end
  73.                 Seats[math.random(1, #Seats)]:Sit(Player.Character.Humanoid)
  74.                 game.ServerStorage.LeaveGui:Clone().Parent = Player.PlayerGui
  75.                 GuiPart.SurfaceGui.Players.Text = "Players: "..#List.." / "..MaxPlayers
  76.             end
  77.         end
  78.         Player.CharacterRemoving:connect(function(character)
  79.             removeFromList(character)
  80.         end)
  81.     end
  82. end)
  83.  
  84. game.ReplicatedStorage.LeaveGuiEvent.OnServerEvent:Connect(function(player)
  85.     player:LoadCharacter()
  86. end)
  87.  
  88. while wait() do
  89.     Timer = 41
  90.     for i=1,Timer do
  91.         Timer = Timer - 1
  92.         GuiPart.SurfaceGui.timeLabel.Text = "Time: "..Timer
  93.         wait(1)
  94.     end
  95.     TeleportPlayers()
  96. end
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement