Hello! I am trying to create a system that lets you join a game when a timer has ended.
The issue is that when the game tries to teleport people for the second time, it does not end up teleporting them. This does work the first time, and the second time it all works until it tries to teleport people.
local joined = game.Workspace.Data.Touched -- The part that they touch to queue up
local TeleportService = game:GetService('TeleportService')
local players = game:GetService('Players')
local GameId = -- Removed in the example
local Timer = game.Workspace.Room.TimerWall.SurfaceGui.TextLabel
local Players = game.Workspace.Data.InGame -- IntValue that tracks how many people are in the queue
local Teleporting = {}
local Count = 60
local function Teleport()
for _, touched in pairs(joined:GetChildren()) do
if touched:IsA('BoolValue') then
if touched.Value == true then
table.insert(Teleporting, players:FindFirstChild(touched.Name)) -- Adds to the teleporting table the player that is marked as being able to teleport.
end
end
end
-- When the table has all the players, the game will teleport every player in the table.
TeleportService:TeleportAsync(GameId, Teleporting)
Players.Value = 0
end
while true do
wait(1)
if Count > 0 and Players.Value > 1 then
Count -= 1
Timer.Text = tostring(Players.Value)..'/24 '..Count..' Seconds left'
else
if Players.Value > 1 then
Timer.Text = 'Teleporting...'
Teleport()
wait(15)
Count = 60
else
Count = 60
Timer.Text = 'The round will not start until there are 2+ players.'
end
end
end
Sorry if my code is bad, I am still a beginner.