Sungmingamerpro13

Story Game Lobby MainScript/TouchGameTeleportScript

Mar 7th, 2026 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 2.75 KB | None | 0 0
  1. local TS = game:GetService("TeleportService")
  2. local TweenService = game:GetService("TweenService")
  3. local placeId = "4587775222"
  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.  
  13. local function updateGui()
  14.     gui.Frame.players.Text = #list
  15.     billboard.Frame.players.Text = #list
  16. end
  17.  
  18. local function removeFromList(character)
  19.     for i=1,#list do
  20.         if list[i] == character.Name then
  21.             table.remove(list,i)
  22.             updateGui()
  23.         end
  24.     end
  25. end
  26.  
  27. local function teleportPlayers()
  28.     if #list > 0 then
  29.         script.Parent.GuiPart.SurfaceGui.Frame.Status.Text = "TELEPORTING"
  30.         script.Parent.GuiPart.SurfaceGui.Frame.Status.TextColor3 = Color3.new(1,0,0)
  31.         local playersToTeleport = {}
  32.         local teleportTime = 0
  33.         for i=1,#list do
  34.             if game.Players:FindFirstChild(list[i]) then
  35.                 table.insert(playersToTeleport,game.Players:FindFirstChild(list[i]))
  36.                 TransitionEvent:FireClient(game.Players:FindFirstChild(list[i]))
  37.             else
  38.                 table.remove(list,i)   
  39.             end
  40.         end
  41.         local code = TS:ReserveServerAsync()(placeId)
  42.         teleporting = true
  43.         TS:TeleportToPrivateServer(placeId,code,playersToTeleport)
  44.         repeat wait() until #list <= 0
  45.         script.Parent.GuiPart.SurfaceGui.Frame.Status.Text = "READY"
  46.         script.Parent.GuiPart.SurfaceGui.Frame.Status.TextColor3 = Color3.new(34/255,255/255,20/255)
  47.         teleporting = false
  48.     end
  49. end
  50.  
  51. script.Parent.Gate.Touched:Connect(function(hit)
  52.     if hit.Parent:findFirstChild("Humanoid") then
  53.         if teleporting == false then
  54.             local char = hit.Parent
  55.             local player = game.Players:FindFirstChild(char.Name)
  56.             local alreadyExists = false
  57.            
  58.             for i=1,#list do
  59.                 if list[i] == char.Name then
  60.                     alreadyExists = true
  61.                 end
  62.             end
  63.            
  64.             if alreadyExists == false then
  65.                 if #list < 16 then
  66.                     table.insert(list,char.Name)
  67.                     char.PrimaryPart.CFrame = spawnTeleport.CFrame
  68.                     updateGui()
  69.                     leaveGuiEvent:FireClient(player)
  70.                 end
  71.                
  72.                 player.CharacterRemoving:connect(function(character)
  73.                     removeFromList(character)
  74.                 end)
  75.             end
  76.            
  77.         end
  78.     end
  79. end)
  80.  
  81. leaveGuiEvent.OnServerEvent:Connect(function(player)
  82.     if player.Character then
  83.         player.Character.HumanoidRootPart.Anchored = false
  84.         wait()
  85.         player.Character.Humanoid.Jump = true
  86.         wait()
  87.         player.Character:MoveTo(game.Workspace.leaveRoomPart.Position)
  88.         removeFromList(player.Character)
  89.     end
  90. end)
  91.  
  92. while wait() do
  93.     timer = 30
  94.     for i=1,timer do
  95.         timer = timer - 1
  96.         gui.Frame.time.Text = timer
  97.         billboard.Frame.time.Text = timer
  98.         wait(1)
  99.     end
  100.     teleportPlayers()
  101. end
Advertisement
Add Comment
Please, Sign In to add comment