Hello, I am creating a system in my Roblox game that displays a player count for a specific private server based on the target PrivateServerId. From my knowledge, I don’t think it’s possible to “invoke” another server using MessagingService, so I tried out a system that bounces back data (MessagingService Async) and validates it through the parameters of the Data. This is messy and also doesn’t work too well.
What is another way I can accomplish this using MessagingService? Is there an easier way to “invoke” a specific server and be able to return the player count?
local MS = game:GetService("MessagingService")
local PS = game.PrivateServerId
MS:SubscribeAsync("Order_"..PS, function()
MS:PublishAsync("Response_"..PS, #game:GetService("Players"):GetPlayers())
end)
Script that asks for the information:
local MS = game:GetService("MessagingService")
local function GetNumberOfPlayers(PrivateServerId: number): number?
local Players = nil
local RBX = MS:SubscribeAsync("Response_"..PrivateServerId, function(Amount)
Players = Amount
end)
MS:PublishAsync("Order_"..PrivateServerId, "")
-- Wait --
local MaxWait = 10
while not Players and MaxWait > 0 do MaxWait -= game:GetService("RunService").Heartbeat:Wait() end
RBX:Disconnect()
return Players
end
you can change 10, keep in mind that it can wait infinitely if the server is not activated.