Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Server Side
- local CollectionService = game:GetService("CollectionService")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local TeleportService = game:GetService("TeleportService")
- local SafeTeleport = require(ReplicatedStorage:WaitForChild("SafeTeleport"))
- local Signs = workspace:WaitForChild("Signs")
- local Id = 77744045792767
- local timer = 3
- local Cells = {
- ["2Players"] = {
- ["1"] = { TimerRunning = false, Players = {} }, -- Cell Number 1
- ["2"] = { TimerRunning = false, Players = {} }, -- Cell Number 2
- Limit = 2,
- },
- ["3Players"] = {
- ["1"] = { TimerRunning = false, Players = {} }, -- etc.
- ["2"] = { TimerRunning = false, Players = {} },
- Limit = 3,
- },
- ["4Players"] = {
- ["1"] = { TimerRunning = false, Players = {} },
- ["2"] = { TimerRunning = false, Players = {} },
- Limit = 4,
- },
- }
- local PlayerJoinCD = {}
- local function handleTeleportation(v, playersInCell, cellInfo, limit)
- local playerIds = {}
- for _, player in ipairs(playersInCell) do
- table.insert(playerIds, player.UserId)
- end
- local TeleportOptions = Instance.new("TeleportOptions")
- TeleportOptions.ShouldReserveServer = true
- local success, result = SafeTeleport(Id, playersInCell, TeleportOptions)
- if not success then
- warn("Teleport failed:", result)
- end
- local allTeleported = false
- for i = 1, 30 do
- allTeleported = true
- for _, player in ipairs(playersInCell) do
- if player.Parent then
- allTeleported = false
- break
- end
- end
- if allTeleported then break end
- wait(1)
- end
- if not allTeleported then
- for _, player in ipairs(playersInCell) do
- if player.Parent then
- player:Kick("Teleportation failed. Please rejoin the game to resolve the issue.")
- end
- end
- end
- table.clear(playersInCell)
- cellInfo.TimerRunning = false
- v.Parent.BillboardGui.Frame.TextLabel.Text = "0/" .. limit
- v.Parent.Timer.TextLabel.Text = ""
- for _, label in ipairs(v.Parent.PlayersList:GetChildren()) do
- if label:IsA("ImageLabel") then
- label.Name = "Empty"
- label.Image = ""
- label.Visible = false
- end
- end
- end
- local function onPlayerTouched(v, hit)
- if not hit.Parent:FindFirstChild("Humanoid") then return end
- local player = game.Players:GetPlayerFromCharacter(hit.Parent)
- if not player then return end
- if table.find(PlayerJoinCD, player) then return end
- for cellType, cellData in pairs(Cells) do
- for cellNumber, cellInfo in pairs(cellData) do
- if type(cellInfo) == "table" then
- for i, cellPlayer in ipairs(cellInfo.Players) do
- if cellPlayer == player then return end
- end
- end
- end
- end
- local cellInfo = Cells[v.Parent.Name][tostring(v.Parent:GetAttribute("Number"))]
- local cellNumber = Cells
- local playersInCell = cellInfo.Players
- local limit = Cells[v.Parent.Name].Limit
- if #playersInCell < limit and not table.find(playersInCell, player) and v.Parent.BillboardGui.Frame.TextLabel.Text ~= "Teleporting.." then
- table.insert(playersInCell, player)
- local thumbnail = game.Players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
- local imageLabel = v.Parent.PlayersList:FindFirstChild("Empty")
- if imageLabel then
- imageLabel.Image = thumbnail
- imageLabel.Name = player.Name
- imageLabel.Visible = true
- end
- v.Parent.BillboardGui.Frame.TextLabel.Text = #playersInCell .. "/" .. limit
- if not cellInfo.TimerRunning then
- cellInfo.TimerRunning = true
- coroutine.wrap(function()
- for i = timer, 1, -1 do
- if not cellInfo.TimerRunning then
- break
- end
- if i == 1 then
- for i,v in cellInfo.Players do
- ReplicatedStorage.Gui:FireClient(v, "Leave")
- end
- v.Parent.Timer.TextLabel.Text = "Teleporting.."
- else
- v.Parent.Timer.TextLabel.Text = "Teleporting in " .. i
- end
- wait(1)
- end
- if cellInfo.TimerRunning then
- handleTeleportation(v, playersInCell, cellInfo, limit)
- end
- end)()
- end
- ReplicatedStorage.Gui:FireClient(player, "Leave")
- hit.Parent:SetPrimaryPartCFrame(v.Parent:FindFirstChild("TouchRoof").CFrame + Vector3.new(0 , -15, 0))
- ReplicatedStorage.Gui:FireClient(player, "NotificationSuccess", "✅You have successfully entered!")
- else
- if #playersInCell == limit and not table.find(playersInCell, player) then
- ReplicatedStorage.Gui:FireClient(player, "NotificationFail", "❌The Current Cell is Full!")
- end
- end
- end
- for _, v in ipairs(CollectionService:GetTagged("Touch")) do
- v.Touched:Connect(function(hit)
- onPlayerTouched(v, hit)
- end)
- end
- ReplicatedStorage.Gui.OnServerEvent:Connect(function(player)
- for cellType, cellData in pairs(Cells) do
- for cellNumber, cellInfo in pairs(cellData) do
- if type(cellInfo) == "table" then
- for i, cellPlayer in ipairs(cellInfo.Players) do
- if cellPlayer == player then
- table.insert(PlayerJoinCD, player)
- task.delay(1, function()
- table.remove(PlayerJoinCD, table.find(PlayerJoinCD, player))
- end)
- player.Character:SetPrimaryPartCFrame(workspace.SpawnLocation.CFrame + Vector3.new(0,5,0))
- table.remove(cellInfo.Players, i)
- for _, sign in ipairs(Signs:GetChildren()) do
- if sign.Name == cellType and tostring(sign:GetAttribute("Number")) == cellNumber then
- local label = sign.PlayersList:FindFirstChild(player.Name)
- if label then
- label.Name = "Empty"
- label.Image = ""
- label.Visible = false
- sign.BillboardGui.Frame.TextLabel.Text = #cellInfo.Players .. "/" .. cellData.Limit
- if #cellInfo.Players == 0 then
- table.clear(cellInfo.Players)
- cellInfo.TimerRunning = false
- sign.BillboardGui.Frame.TextLabel.Text = "0/" .. cellData.Limit
- sign.Timer.TextLabel.Text = ""
- for _, label in ipairs(sign.PlayersList:GetChildren()) do
- if label:IsA("ImageLabel") then
- label.Name = "Empty"
- label.Image = ""
- label.Visible = false
- end
- end
- end
- break
- end
- end
- end
- break
- end
- end
- end
- end
- end
- end)
- for _, sign in ipairs(Signs:GetChildren()) do
- local limit = Cells[sign.Name].Limit
- sign.BillboardGui.Frame.TextLabel.Text = "0/" .. limit
- end
- game.Players.PlayerRemoving:Connect(function(player)
- if table.find(PlayerJoinCD, player) then
- table.remove(PlayerJoinCD, table.find(PlayerJoinCD, player))
- end
- for cellType, cellData in pairs(Cells) do
- for cellNumber, cellInfo in pairs(cellData) do
- if type(cellInfo) == "table" then
- for i, cellPlayer in ipairs(cellInfo.Players) do
- if cellPlayer == player then
- table.remove(cellInfo.Players, i)
- for _, sign in ipairs(Signs:GetChildren()) do
- if sign.Name == cellType and tostring(sign:GetAttribute("Number")) == cellNumber then
- local label = sign.PlayersList:FindFirstChild(player.Name)
- if label then
- label.Name = "Empty"
- label.Image = ""
- label.Visible = false
- end
- sign.BillboardGui.Frame.TextLabel.Text = #cellInfo.Players .. "/" .. cellData.Limit
- if #cellInfo.Players == 0 then
- table.clear(cellInfo.Players)
- cellInfo.TimerRunning = false
- sign.BillboardGui.Frame.TextLabel.Text = "0/" .. cellData.Limit
- sign.Timer.TextLabel.Text = ""
- for _, label in ipairs(sign.PlayersList:GetChildren()) do
- if label:IsA("ImageLabel") then
- label.Name = "Empty"
- label.Image = ""
- label.Visible = false
- end
- end
- end
- break
- end
- end
- break
- end
- end
- end
- end
- end
- end)
- ReplicatedStorage.RemoteFunction.OnServerEvent:Connect(function(player)
- ReplicatedStorage.RemoteFunction:FireClient(player, Cells)
- end)
- ------------------------------------------------------------------------------------------------------------
- -- Client Side
- local rep = game:GetService("ReplicatedStorage")
- local player = game:GetService("Players").LocalPlayer
- local Notification = require(player.PlayerGui:WaitForChild("NotificationSystem"):WaitForChild("NotificationModule"))
- local ScreenGui = player.PlayerGui:WaitForChild("Leave")
- ScreenGui.Enabled = false
- local cd = false
- local cd2 = false
- rep.Gui.OnClientEvent:Connect(function(Status: "Leave"|"NotificationSuccess"|"NotificationFail",Text)
- if Status == "Leave" then
- if ScreenGui.Enabled == false then
- ScreenGui.Enabled = true
- ScreenGui.Frame.MouseButton1Click:Once(function()
- ScreenGui.Enabled = false
- rep.Gui:FireServer()
- end)
- else
- ScreenGui.Enabled = false
- end
- elseif Status == "NotificationSuccess" then
- if cd2 == false then
- cd2 = true
- Notification.NewSucess(Text, 3)
- task.delay(2, function()
- cd2 = false
- end)
- end
- elseif Status == "NotificationFail" then
- if cd == false then
- cd = true
- Notification.NewError(Text, 3)
- task.delay(2, function()
- cd = false
- end)
- end
- end
- end)
- while task.wait() do
- for i,v in workspace.Signs:GetChildren() do
- task.wait(0.01)
- v.BillboardGui.Frame.UIGradient.Rotation += 1
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment