local players = {}
local teleporting = false
local tpService = game:GetService("TeleportService")
local TweenService = game:GetService("TweenService")
local info = TweenInfo.new(1.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false)
local close = TweenService:Create(script.Parent.Parent.door, info, {Size = script.Parent.Parent.final.Size, Position = script.Parent.Parent.final.Position})
local open = TweenService:Create(script.Parent.Parent.door, info, {Size = script.Parent.Parent.start.Size, Position = script.Parent.Parent.start.Position})
local max = 8
local function countdown()
for i=30, 0, -1 do
script.Parent.Parent.TimeLeft.Value = i
script.Parent.Parent.display.BillboardGui.time.Text = i
task.wait(1)
end
end
script.Parent.Parent.TimeLeft.Changed:Connect(function()
if script.Parent.Parent.TimeLeft.Value == 0 then
teleporting = true
close:Play()
local code = tpService:ReserveServer(11106583075)
task.wait(2)
tpService:TeleportToPrivateServer(11106583075, code, players)
for k in pairs (players) do
players[k] = nil
end
task.wait(5)
open:Play()
teleporting = false
script.Parent.Parent.TimeLeft.Value = 30
countdown()
end
end)
script.Parent.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
local inTable = table.find(players,hit.Parent.Name)
local plr = game.Players:FindFirstChild(hit.Parent.Name)
if inTable then return end
if #players >= max then return end
if hum and teleporting == false then
table.insert(players,hit.Parent.Name)
print(#players)
script.Parent.Parent.display.BillboardGui.TextLabel.Text = (#players).. "/" ..max
hit.Parent.HumanoidRootPart.CFrame = script.Parent.Parent.tp.CFrame
plr.PlayerGui.ElevatorGui.Enabled = true
end
end)
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
table.remove(players,players[player.Name])
script.Parent.Parent.display.BillboardGui.TextLabel.Text = (#players).. "/" ..max
local char = player.Character
char.HumanoidRootPart.CFrame = script.Parent.Parent.tpleave.CFrame
player.PlayerGui.ElevatorGui.Enabled = false
end)
countdown()
-- inserting string
table.insert(players,hit.Parent.Name)
-- how to insert player object
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player then
table.insert(players, player)
end