Advertisement
RobBobDev

Player Based Teleportation with Tables

May 27th, 2022 (edited)
645
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local TS = game:GetService("TeleportService")
  2. local PlaceId = 9742098314
  3. local code = TS:ReserveServer(9742098314)
  4. local player = game.Players
  5.  
  6. local WaitTime = 5 --Change this to change the wait time (Seconds)
  7.  
  8. local gate = script.Parent
  9. local exit = workspace.DeTeleporter
  10. local list = {}
  11. local ui = script.Parent.SurfaceGui
  12. local canAdd = true
  13. local tpPos = workspace.TpPos
  14. local exitpos = workspace.DeTpPos
  15. local gamepos = workspace.GameSpawn
  16.  
  17. while true do
  18.  
  19. gate.Touched:Connect(function(otherpart)
  20.     if canAdd == true then
  21.        
  22.             canAdd = false
  23.             if otherpart.Parent:IsA("Accessory") then
  24.                 print("Accessory")
  25.                 table.insert(list, otherpart.Parent.Parent.Name)
  26.                 otherpart.Parent.Parent:MoveTo(tpPos.Position)
  27.             else
  28.         table.insert(list, otherpart.Parent.Name)
  29.         print(list)
  30.         otherpart.Parent:MoveTo(tpPos.Position)
  31.         end
  32.         ui.Players.Text = "/20"
  33.         ui.Players.Text = #list.. ui.Players.Text
  34.         wait(3)
  35.         canAdd = true
  36.     end
  37. end)
  38.  
  39. exit.Touched:Connect(function(otherpart)
  40.     if canAdd == true then
  41.  
  42.         canAdd = false
  43.         local plr = table.find(list, otherpart.Parent.Name)
  44.         table.remove(list, plr)
  45.         otherpart.Parent:MoveTo(exitpos.Position)
  46.         print(list)
  47.        
  48.         ui.Players.Text = "/20"
  49.             ui.Players.Text = #list.. ui.Players.Text
  50.             if ui.Players.Text == "0/20" then
  51.                 ui.Timer.Text = ""
  52.             end
  53.         wait(3)
  54.         canAdd = true
  55.     end
  56. end)
  57.  
  58. if #list > 0 then
  59.         for i = WaitTime,0,-1 do
  60.             if ui.Players.Text == "0/20" then
  61.                 break
  62.             else
  63.         ui.Timer.Text = i
  64.                 wait(1)
  65.                 end
  66.             end
  67.     end
  68.    
  69.     if ui.Timer.Text == "0" then
  70.         print(list)
  71.         for _, v in ipairs(list) do
  72.             print(list)
  73.             local plr = player:GetPlayerFromCharacter(game.Workspace:FindFirstChild(v))
  74.             print(plr)
  75.             TS:TeleportToPrivateServer(9742098314, code, plr)
  76.             code = TS:ReserveServer(9742098314)
  77.         end
  78.         table.clear(list)
  79.         ui.Timer.Text = ""
  80.         ui.Players.Text = "0/20"
  81.     end
  82.    
  83.     wait()
  84.     end
Advertisement
RAW Paste Data Copied
Advertisement