mfx832

Untitled

Jan 12th, 2025 (edited)
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.18 KB | None | 0 0
  1. --Server Side
  2. local CollectionService = game:GetService("CollectionService")
  3. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  4. local TeleportService = game:GetService("TeleportService")
  5. local SafeTeleport = require(ReplicatedStorage:WaitForChild("SafeTeleport"))
  6. local Signs = workspace:WaitForChild("Signs")
  7.  
  8. local Id = 77744045792767
  9.  
  10. local timer = 3
  11. local Cells = {
  12.     ["2Players"] = {
  13.         ["1"] = { TimerRunning = false, Players = {} }, -- Cell Number 1
  14.         ["2"] = { TimerRunning = false, Players = {} }, -- Cell Number 2
  15.         Limit = 2,
  16.     },
  17.     ["3Players"] = {
  18.         ["1"] = { TimerRunning = false, Players = {} }, -- etc.
  19.         ["2"] = { TimerRunning = false, Players = {} },
  20.         Limit = 3,
  21.     },
  22.     ["4Players"] = {
  23.         ["1"] = { TimerRunning = false, Players = {} },
  24.         ["2"] = { TimerRunning = false, Players = {} },
  25.         Limit = 4,
  26.     },
  27. }
  28.  
  29. local PlayerJoinCD = {}
  30.  
  31. local function handleTeleportation(v, playersInCell, cellInfo, limit)
  32.     local playerIds = {}
  33.     for _, player in ipairs(playersInCell) do
  34.         table.insert(playerIds, player.UserId)
  35.     end
  36.  
  37.     local TeleportOptions = Instance.new("TeleportOptions")
  38.     TeleportOptions.ShouldReserveServer = true
  39.  
  40.     local success, result = SafeTeleport(Id, playersInCell, TeleportOptions)
  41.     if not success then
  42.         warn("Teleport failed:", result)
  43.     end
  44.  
  45.     local allTeleported = false
  46.     for i = 1, 30 do
  47.         allTeleported = true
  48.         for _, player in ipairs(playersInCell) do
  49.             if player.Parent then
  50.                 allTeleported = false
  51.                 break
  52.             end
  53.         end
  54.  
  55.         if allTeleported then break end
  56.         wait(1)
  57.     end
  58.  
  59.     if not allTeleported then
  60.         for _, player in ipairs(playersInCell) do
  61.             if player.Parent then
  62.                 player:Kick("Teleportation failed. Please rejoin the game to resolve the issue.")
  63.             end
  64.         end
  65.     end
  66.  
  67.     table.clear(playersInCell)
  68.     cellInfo.TimerRunning = false
  69.     v.Parent.BillboardGui.Frame.TextLabel.Text = "0/" .. limit
  70.     v.Parent.Timer.TextLabel.Text = ""
  71.  
  72.     for _, label in ipairs(v.Parent.PlayersList:GetChildren()) do
  73.         if label:IsA("ImageLabel") then
  74.             label.Name = "Empty"
  75.             label.Image = ""
  76.             label.Visible = false
  77.         end
  78.     end
  79. end
  80.  
  81. local function onPlayerTouched(v, hit)
  82.     if not hit.Parent:FindFirstChild("Humanoid") then return end
  83.     local player = game.Players:GetPlayerFromCharacter(hit.Parent)
  84.     if not player then return end
  85.     if table.find(PlayerJoinCD, player) then return end
  86.    
  87.     for cellType, cellData in pairs(Cells) do
  88.         for cellNumber, cellInfo in pairs(cellData) do
  89.             if type(cellInfo) == "table" then
  90.                 for i, cellPlayer in ipairs(cellInfo.Players) do
  91.                     if cellPlayer == player then return end
  92.                 end
  93.             end
  94.         end
  95.     end
  96.    
  97.    
  98.  
  99.     local cellInfo = Cells[v.Parent.Name][tostring(v.Parent:GetAttribute("Number"))]
  100.     local cellNumber = Cells
  101.     local playersInCell = cellInfo.Players
  102.     local limit = Cells[v.Parent.Name].Limit
  103.    
  104.  
  105.     if #playersInCell < limit and not table.find(playersInCell, player) and v.Parent.BillboardGui.Frame.TextLabel.Text ~= "Teleporting.." then
  106.         table.insert(playersInCell, player)
  107.  
  108.         local thumbnail = game.Players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
  109.         local imageLabel = v.Parent.PlayersList:FindFirstChild("Empty")
  110.         if imageLabel then
  111.             imageLabel.Image = thumbnail
  112.             imageLabel.Name = player.Name
  113.             imageLabel.Visible = true
  114.         end
  115.  
  116.         v.Parent.BillboardGui.Frame.TextLabel.Text = #playersInCell .. "/" .. limit
  117.  
  118.         if not cellInfo.TimerRunning then
  119.             cellInfo.TimerRunning = true
  120.             coroutine.wrap(function()
  121.                 for i = timer, 1, -1 do
  122.                     if not cellInfo.TimerRunning then
  123.                         break
  124.                     end
  125.                    
  126.                     if i == 1 then
  127.                         for i,v in cellInfo.Players do
  128.                             ReplicatedStorage.Gui:FireClient(v, "Leave")
  129.                         end
  130.                         v.Parent.Timer.TextLabel.Text = "Teleporting.."
  131.                     else
  132.                         v.Parent.Timer.TextLabel.Text = "Teleporting in " .. i
  133.                     end
  134.                     wait(1)
  135.                 end
  136.  
  137.                 if cellInfo.TimerRunning then
  138.                     handleTeleportation(v, playersInCell, cellInfo, limit)
  139.                 end
  140.             end)()
  141.         end
  142.  
  143.         ReplicatedStorage.Gui:FireClient(player, "Leave")
  144.  
  145.  
  146.             hit.Parent:SetPrimaryPartCFrame(v.Parent:FindFirstChild("TouchRoof").CFrame + Vector3.new(0 , -15, 0))
  147.             ReplicatedStorage.Gui:FireClient(player, "NotificationSuccess", "✅You have successfully entered!")
  148.     else
  149.         if #playersInCell == limit and not table.find(playersInCell, player) then
  150.             ReplicatedStorage.Gui:FireClient(player, "NotificationFail", "❌The Current Cell is Full!")
  151.         end
  152.     end
  153. end
  154.  
  155. for _, v in ipairs(CollectionService:GetTagged("Touch")) do
  156.     v.Touched:Connect(function(hit)
  157.         onPlayerTouched(v, hit)
  158.     end)
  159. end
  160.  
  161. ReplicatedStorage.Gui.OnServerEvent:Connect(function(player)
  162.     for cellType, cellData in pairs(Cells) do
  163.         for cellNumber, cellInfo in pairs(cellData) do
  164.             if type(cellInfo) == "table" then
  165.                 for i, cellPlayer in ipairs(cellInfo.Players) do
  166.                     if cellPlayer == player then
  167.                         table.insert(PlayerJoinCD, player)
  168.                         task.delay(1, function()
  169.                             table.remove(PlayerJoinCD, table.find(PlayerJoinCD, player))
  170.                         end)
  171.                         player.Character:SetPrimaryPartCFrame(workspace.SpawnLocation.CFrame + Vector3.new(0,5,0))
  172.                         table.remove(cellInfo.Players, i)
  173.                         for _, sign in ipairs(Signs:GetChildren()) do
  174.                             if sign.Name == cellType and tostring(sign:GetAttribute("Number")) == cellNumber then
  175.                                 local label = sign.PlayersList:FindFirstChild(player.Name)
  176.                                 if label then
  177.                                     label.Name = "Empty"
  178.                                     label.Image = ""
  179.                                     label.Visible = false
  180.                                     sign.BillboardGui.Frame.TextLabel.Text = #cellInfo.Players .. "/" .. cellData.Limit
  181.                                     if #cellInfo.Players == 0 then
  182.                                         table.clear(cellInfo.Players)
  183.                                         cellInfo.TimerRunning = false
  184.                                         sign.BillboardGui.Frame.TextLabel.Text = "0/" .. cellData.Limit
  185.                                         sign.Timer.TextLabel.Text = ""
  186.                                         for _, label in ipairs(sign.PlayersList:GetChildren()) do
  187.                                             if label:IsA("ImageLabel") then
  188.                                                 label.Name = "Empty"
  189.                                                 label.Image = ""
  190.                                                 label.Visible = false
  191.                                             end
  192.                                         end
  193.                                     end
  194.                                     break
  195.                                 end
  196.                             end
  197.                         end
  198.                         break
  199.                     end
  200.                 end
  201.             end
  202.         end
  203.     end
  204. end)
  205.  
  206. for _, sign in ipairs(Signs:GetChildren()) do
  207.     local limit = Cells[sign.Name].Limit
  208.     sign.BillboardGui.Frame.TextLabel.Text = "0/" .. limit
  209. end
  210.  
  211. game.Players.PlayerRemoving:Connect(function(player)
  212.     if table.find(PlayerJoinCD, player) then
  213.         table.remove(PlayerJoinCD, table.find(PlayerJoinCD, player))
  214.     end
  215.  
  216.     for cellType, cellData in pairs(Cells) do
  217.         for cellNumber, cellInfo in pairs(cellData) do
  218.             if type(cellInfo) == "table" then
  219.                 for i, cellPlayer in ipairs(cellInfo.Players) do
  220.                     if cellPlayer == player then
  221.                         table.remove(cellInfo.Players, i)
  222.  
  223.                         for _, sign in ipairs(Signs:GetChildren()) do
  224.                             if sign.Name == cellType and tostring(sign:GetAttribute("Number")) == cellNumber then
  225.                                 local label = sign.PlayersList:FindFirstChild(player.Name)
  226.                                 if label then
  227.                                     label.Name = "Empty"
  228.                                     label.Image = ""
  229.                                     label.Visible = false
  230.                                 end
  231.  
  232.                                 sign.BillboardGui.Frame.TextLabel.Text = #cellInfo.Players .. "/" .. cellData.Limit
  233.  
  234.                                 if #cellInfo.Players == 0 then
  235.                                     table.clear(cellInfo.Players)
  236.                                     cellInfo.TimerRunning = false
  237.                                     sign.BillboardGui.Frame.TextLabel.Text = "0/" .. cellData.Limit
  238.                                     sign.Timer.TextLabel.Text = ""
  239.  
  240.                                     for _, label in ipairs(sign.PlayersList:GetChildren()) do
  241.                                         if label:IsA("ImageLabel") then
  242.                                             label.Name = "Empty"
  243.                                             label.Image = ""
  244.                                             label.Visible = false
  245.                                         end
  246.                                     end
  247.                                 end
  248.  
  249.                                 break
  250.                             end
  251.                         end
  252.  
  253.                         break
  254.                     end
  255.                 end
  256.             end
  257.         end
  258.     end
  259. end)
  260.  
  261.  
  262. ReplicatedStorage.RemoteFunction.OnServerEvent:Connect(function(player)
  263.     ReplicatedStorage.RemoteFunction:FireClient(player, Cells)
  264. end)
  265.  
  266.  
  267. ------------------------------------------------------------------------------------------------------------
  268. -- Client Side
  269.  
  270. local rep = game:GetService("ReplicatedStorage")
  271. local player = game:GetService("Players").LocalPlayer
  272. local Notification = require(player.PlayerGui:WaitForChild("NotificationSystem"):WaitForChild("NotificationModule"))
  273.  
  274. local ScreenGui = player.PlayerGui:WaitForChild("Leave")
  275. ScreenGui.Enabled = false
  276.  
  277. local cd = false
  278. local cd2 = false
  279.  
  280. rep.Gui.OnClientEvent:Connect(function(Status: "Leave"|"NotificationSuccess"|"NotificationFail",Text)
  281.     if Status == "Leave" then
  282.         if ScreenGui.Enabled == false then
  283.             ScreenGui.Enabled = true
  284.  
  285.             ScreenGui.Frame.MouseButton1Click:Once(function()
  286.                 ScreenGui.Enabled = false
  287.                 rep.Gui:FireServer()
  288.             end)
  289.         else
  290.             ScreenGui.Enabled = false
  291.         end
  292.    
  293.     elseif Status == "NotificationSuccess" then
  294.         if cd2 == false then
  295.             cd2 = true
  296.             Notification.NewSucess(Text, 3)
  297.             task.delay(2, function()
  298.                 cd2 = false
  299.             end)
  300.         end
  301.        
  302.     elseif Status == "NotificationFail" then
  303.         if cd == false then
  304.             cd = true
  305.             Notification.NewError(Text, 3)
  306.             task.delay(2, function()
  307.                 cd = false
  308.             end)
  309.         end
  310.     end
  311. end)
  312.  
  313. while task.wait() do
  314.     for i,v in workspace.Signs:GetChildren() do
  315.         task.wait(0.01)
  316.         v.BillboardGui.Frame.UIGradient.Rotation += 1
  317.     end
  318. end
  319.  
  320.  
Advertisement
Add Comment
Please, Sign In to add comment