CCCPaste

STORY GAME LOBBYHandler

local placeId = 11155396403
local tps = game:GetService("TeleportService")

local ts = game:GetService("TweenService")

local lifts = workspace:WaitForChild("Lobby"):WaitForChild("Lifts")


for i, lift in pairs(lifts:GetChildren()) do

local playerLimit = tonumber(lift.Name)

local front = lift:WaitForChild("Front")

local gui = Instance.new("SurfaceGui")
gui.PixelsPerStud = 60
gui.SizingMode = Enum.SurfaceGuiSizingMode.PixelsPerStud
gui.Parent = front

local label = Instance.new("TextLabel")
label.Font = Enum.Font.Michroma
label.BackgroundTransparency = 1
label.TextColor3 = Color3.fromRGB(255, 255, 255)
label.TextScaled = true
label.Size = UDim2.new(1, 0, 1, 0)
label.Text = "0/" .. playerLimit
label.Parent = gui


local playersIn = {}
local playerDebounce = {}

front.Touched:Connect(function(hit)

local char = hit.Parent
local plr = game.Players:GetPlayerFromCharacter(char)

if plr and not playerDebounce[plr] then

playerDebounce[plr] = true

if table.find(playersIn, plr) then
table.remove(playersIn, table.find(playersIn, plr))

char.HumanoidRootPart.CFrame = front.CFrame + front.CFrame.LookVector * 3

elseif #playersIn < playerLimit then
table.insert(playersIn, plr)

char.HumanoidRootPart.CFrame = lift.Lift.PrimaryPart.CFrame + Vector3.new(0, 5, 0)
end

task.wait(1)
playerDebounce[plr] = false
end
end)


local countdown = 31

local cfValue = Instance.new("CFrameValue")
cfValue.Value = lift.Lift.PrimaryPart.CFrame

cfValue:GetPropertyChangedSignal("Value"):Connect(function()
lift.Lift:SetPrimaryPartCFrame(cfValue.Value)
end)


task.spawn(function()
while task.wait(1) do
if #playersIn > 0 then
countdown -= 1
else
countdown = 31
end

label.Text = #playersIn .. "/" .. playerLimit .. "\n" .. countdown .. "s"

if countdown <= 0 then

local ti = TweenInfo.new(4.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
local originalCF = cfValue.Value
local goalCF = originalCF - Vector3.new(0, 16, 0)

ts:Create(cfValue, ti, {Value = goalCF}):Play()

task.wait(5)

local options = Instance.new("TeleportOptions")
options.ShouldReserveServer = true

tps:TeleportAsync(placeId, playersIn, options)

ts:Create(cfValue, ti, {Value = originalCF})

playersIn = {}
end
end
end)
end