Remote function returning Dictionary as nil

I’m trying to create a server list for clients that want to join servers of a different place. The script calls a remotefunction in the server, to which the server sends a message using messagingservice to all the servers in the place and then all of the servers in that place send the individual details that I need back using messaging service, such as the jobid, the number of players and the gamemode of the match going on in that server. All of this comes via dictionary, something like:

Servers = {}
local data = message.Data
local serverid,players,gamemode = data.ServerId,data.Players,data.Gamemode
		
local Details = {
	Players = players,
	Gamemode = gamemode
}
		
		
Servers[tostring(serverid)] = Details

The issue is, whenever I use return Servers and regain the value back in the local script, the output will come as nil, like such:

local servers = game.ReplicatedStorage.Events.GetServers:InvokeServer()
print("As string: "..tostring(servers)) --Prints "nil"

I’ve looked into documentation and other topics, some mentioned objects could not be passed through, and others mentioned mixed values in a dictionary so I’ve tried the following:

1 - Tried to change all of the values returned as string, something like:

Servers = {}
local data = message.Data
local serverid,players,gamemode = data.ServerId,data.Players,data.Gamemode
		
local Details = {
	["Players"] = players,
	["Gamemode"] = gamemode
}
		
		
Servers[tostring(serverid)] = TableOfThings

2 - I even tried to return a simpler dictionary, like:

local Servers = {
	["Test server"] = {"Players","Gamemode"}
}

return Servers

As for last, here’s the code that returns the values of the server:

--This is wrapped in a pcall
MessagingService:SubscribeAsync("RequestServers",function(message)
local TableToGive = {
	ServerId = tostring(game.JobId),
	Players = tostring(#game.Players:GetChildren()),
	Gamemode = "Survival"
}
		
MessagingService:PublishAsync("UpdateServers",TableToGive)
end)

I do not understand as to why this is not working or how I can fix it. I can surely find a workaround but, based on documentation online, other players have been able to achieve what I’m trying to archieve, but for some reason I cannot.

Any help is kindly appreciated!

1 Like