MessagingService erroring

Hey programmers! I want to use MessagingService so I can send data between two servers to create a Server List, something like Criminality’s server list.

I have, however, ran into a few issues. At the moment, I am trying to print the ServerId, Player Count and Max Players however I keep on getting errors. I am unable to find out the problem; This may be due to the fact that I don’t understand how MessagingService works. Can anybody pin out the problem in this code?

This is the script that is on Place A (Start Place):

local playersService = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local teleportService = game:GetService("TeleportService")

local values = replicatedStorage:WaitForChild("Values")

local serverData = {
	ServerId = values.ServerId.Value,
	PlayerCount = 0,
	MaxPlayers = 16,
}
		
local function SendData()
	serverData.PlayerCount = #playersService:GetPlayers()
	serverData.MaxPlayers = 16
			
	local success, err = pcall(function()
		messagingService:PublishAsync("SL_Data", serverData)
	end)
	if err then
		warn("Attempt to send server data failed. ERROR: n/", err)
	end
end
		
while true do
	SendData()
	task.wait(2)
end

and this is on Place B:

local messagingService = game:GetService("MessagingService")

while true do
	messagingService:SubscribeAsync("SL_Data", function(message)
		print(message.ServerId)
	end)
	task.wait(1)
end

This is the error I recieve when somebody joins Place B:


Also, doing print(message.Data) doesn’t help as well. It leads to the table name instead of the details I actually want.

Thank you to anybody who helps!

Are you sure script B is causing that error and why did you make it create a new callback every second?

I believe it is on Place B’s script as if nobody is in the game it sends no errors or messages as assumed; it’s only when SubscribeAsync is called (when somebody joins the game) that it starts erroring as it’s attempting to call a value that doesn’t exist. I do however say that with a grain of salt because I don’t understand MessagingService. The developer documentation confused me and so did community tutorials.

And apologies for creating a callback every second. I am unsure why I did that; Probably because I rushed this last script as my previous ones did not work.