Advertisement
Sungmingamerpro13

New MainTeleportScript

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