I have a global matchmaking system, and it uses a table and I wan’t to teleport all players that were in the queue to the SAME server. When I tested, each player got sent to their own server. In my script there is a table named queuedPlayers.
Though when I printed the table it just printed something like “table(randomletters)” and not the queued players. How would I fix this?
--Variables
local memoryStore = game:GetService("MemoryStoreService")
local queue = memoryStore:GetSortedMap("Queue")
local tpService = game:GetService("TeleportService")
local minimum = 1
local maximum = 1
local placeId = 12576175275
local re = game.ReplicatedStorage.MenuRemotes:WaitForChild("Queue")
function addToQueue(player)
queue:SetAsync(player.UserId, player.UserId, 2592000)
end
function removeFromQueue(player)
queue:RemoveAsync(player.UserId)
end
local cooldown = {}
re.OnServerEvent:Connect(function(player, inQueue)
if cooldown[player] then return end
cooldown[player] = true
if inQueue == "IN QUEUE" then
pcall(addToQueue, player)
print("Player in Queue")
elseif inQueue == "QUEUE" then
pcall(removeFromQueue, player)
print("Player not in queue")
end
wait(1)
cooldown[player] = false
end)
game.Players.PlayerRemoving:Connect(removeFromQueue)
local lastOverMin = tick()
while wait(1) do
local success, queuedPlayers = pcall(function()
return queue:GetRangeAsync(Enum.SortDirection.Descending, maximum)
end)
if success then
local amountQueued = 0
for i, data in pairs(queuedPlayers) do
amountQueued += 1
print("Added Player to Queue")
print(amountQueued)
end
if amountQueued < minimum then
print("Not enough players")
lastOverMin = tick()
end
local timeOverMin = tick() - lastOverMin
if timeOverMin >= 15 or amountQueued == maximum then
print("Queue Process Begin")
for i, data in pairs(queuedPlayers) do
local userId = data.value
local player = game.Players:GetPlayerByUserId(userId)
if player then
print("Player found in queue")
local success, err = pcall(function()
print(queuedPlayers)
player.FoundMatch.Value = true
-- tried to fix the tp myself here --
--local code = tpService:ReserveServer(12576175275)
--tpService:TeleportToPrivateServer(12576175275, code, {player})
--tpService:TeleportAsync(placeId, {player})
print("Teleporting")
end)
spawn(function()
if success then
wait(1)
pcall(function()
queue:RemoveAsync(data.key)
end)
end
end)
end
end
end
end
end