Hello. I am trying to pass a table that contains Dedicated Server codes. The sorting number is the actual code that the player types in the join the server. This part works fine.
However, If I try passing the same table with the values in it to another server, all of the code values become nil.
Yes, I did test this. I printed the message.Data while indexing every sorting number by doing this:
for num = 100000,100500 do
print(tostring(num)..": "..tostring(message.Data[num]))
wait()
end
How I am sending the table:
MessagingService:PublishAsync(MESSAGING_TOPIC, table.pack(servers)) --"servers" being the table that I want to pass.
Am I doing something wrong here? Why is the Subscribing system not picking up any codes?
Full system
Each “lobby” server has a 1 player cap. If I remove this and try the joining system, it works because all of the codes are being stored locally. I want to be able to send new codes whenever a player in a different server creates a server.
local TS = game:GetService("TeleportService")
local DSS = game:GetService("DataStoreService")
local MessagingService = game:GetService("MessagingService")
local MESSAGING_TOPIC = "ServerList"
local Reload_Topic = "Reload"
servers = {}
local ran
local newServerEvent = game.ReplicatedStorage.NewServer
local joinServerEvent = game.ReplicatedStorage.JoinServer
local serverRetrieveEvent = game.ReplicatedStorage.SendServerTable
local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
--Set table to nil
for num = 100000,100500 do
servers[num] = nil
end
--//Functions//--
local function CreateNewServer(plr)
ran = math.random(100000,100500)
local code = TS:ReserveServer(6660528936)
table.insert(servers,ran,code)
print(servers[ran])
wait(2)
TS:TeleportToPrivateServer(6660528936,code,{plr},"No Escape - Game",ran)
end
--//Subscriptions//
local subscribeSuccess, subscribeConnection = pcall(function()
return MessagingService:SubscribeAsync(MESSAGING_TOPIC, function(message)
print("Subscribe (recieve): ")
print(message.Data)
for num = 100000,100500 do
print(tostring(num)..": "..tostring(message.Data[num]))
wait()
if (servers[num] == nil) and (message.Data[num] ~= nil) then
servers[num] = message.Data[num]
print(message.Data[num])
wait()
end
end
end)
end)
if subscribeSuccess then
plr.AncestryChanged:Connect(function()
subscribeConnection:Disconnect()
end)
end
--Create new server
newServerEvent.OnServerEvent:Connect(function(plr)
CreateNewServer(plr)
wait(1)
local publishSuccess, publishResult = pcall(function()
MessagingService:PublishAsync(MESSAGING_TOPIC, servers)
end)
if not publishSuccess then
print(publishResult)
else
print("Publish (sent): ")
print(servers)
end
end)
--Join server via code
joinServerEvent.OnServerEvent:Connect(function(plr,text)
print(servers[tonumber(text)])
print(servers[text])
if servers[tonumber(text)] ~= nil then
TS:TeleportToPrivateServer(6660528936,servers[tonumber(text)],{plr},"No Escape - Game")
else
warn("Server does not exist or has not been loaded.")
end
end)