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!