I’m trying to print out some data passed via messagingservice, and the prints return nil for both parameters.
why?
local ms = game:GetService("MessagingService")
local idTable = {
["1"] = 10825692298;
["2"] = 10825692644;
["3"] = 10825692775;
}
local function subscribe()
for i,v in pairs(idTable) do
ms:SubscribeAsync(tostring(v), function(dataCallback)
if dataCallback.ID == nil then
print(dataCallback["ID"], dataCallback["plrNum"])
end
end)
end
end
subscribe()
local function publish()
for i,v in pairs(idTable) do
local data = {
["ID"] = game.GameId;
["plrNum"] = #game.Players:GetChildren()
}
ms:PublishAsync(tostring(v), data)
end
end
local function cycler()
publish()
task.wait(5)
cycler()
end
cycler()
i would not use messaging service for that, i would use datastores and make a universal key that a server will append its server id or whatever as the key and the values(s) can be the number of players and so when one server wants to see how many players are in a server you just have to grave the datastore with the key of the server your looking for.
Just make sure to remove the players from the number when a player leaves and to remove the key entirely when a server shuts down