I’m trying to send the length of a table to a reserved server, then want to compare if the amount of players in the game is equal to the length of the table.
If it doesn’t make sense, check the scripts below
The issue is that the length of the table doesn’t print in the second script. There’s no error in the output. I’ve been searching for answers on the dev forum for quite a while but haven’t been able to find anything so far. Any help is appreciated, thanks in advance.
Script in the lobby place:
local tpService = game:GetService("TeleportService")
local reservedServerCode = tpService:ReserveServer(9222987139)
local repStorage = game:GetService("ReplicatedStorage")
local queueUiEvent = repStorage:WaitForChild("queueUiEvent")
local players = game:GetService("Players")
local messagingService = game:GetService("MessagingService")
local messagingTopic = "queueSizeTopic"
local joinPart = script.Parent
local queue = {}
local maxLength = 2
joinPart.Touched:Connect(function(hit)
local char = hit:FindFirstAncestorOfClass("Model") -- Character that touched part
local player = game:GetService("Players"):GetPlayerFromCharacter(char) -- Player that touched part (from character)
if player and not table.find(queue,player) and #queue < 2 then -- If player's still there and not already in the queue and theres still room
table.insert(queue, player) -- then add player to the queue
for i,v in pairs(queue) do -- Notify players inside the queue
queueUiEvent:FireClient(v, #queue, maxLength, "fillQueue") -- Fire a remote event to players in the queue, sending queue length and max queue length
end
if #queue == maxLength then -- if queue is full, teleport players and empty queue
local success, errormessage = pcall(function()
messagingService:PublishAsync(messagingTopic, maxLength)
end)
tpService:TeleportToPrivateServer(9222987139, reservedServerCode, queue) -- teleport all players
for i,v in pairs(queue) do
queueUiEvent:FireClient(v, #queue, maxLength, "emptyQueue")
end
wait(5)
table.clear(queue) -- Empty queue afterwards
end
end
end)
And script in the other place:
local messagingService = game:GetService("MessagingService")
local messagingTopic = "queueSizeTopic"
local success, errormessage, connection = pcall(function()
messagingService:SubscribeAsync(messagingTopic, function(msg)
print(#msg.Data)
end)
end)