How I can count how much servers has in game?

I need counter how much server has.

example:

local ServerCountInGame = #game:GetAllServers()
print(ServerCountInGame) -- 10 (its example)
3 Likes

What are you using it for? This seems unnecessary.

I don’t think it’s possible to know how much servers are there directly.

I don’t know if there’s any other way, but using MessagingService you can Publish a message and then wait how many “replies” you get

we will now make one transaction for all servers. and we need to give that player a value equal to the sum of the servers we send to that player.
Instead, we’d better get a post again from the servers we sent to. So for example, I sent a message to all servers from a server. Then all the servers I send send a message to the server that I am. the sum of these messages will also equal the number of Servers.

Example:
Script sended message to all servers. All Servers doing this:
game:SendMessage(game.JobId, message)

I know this but I want more easy way

Okay, no problem. I could not think of anything else :smiley:

my module is here.
get my module by clicking here

local Module = require(path.to.module)
local Client = Module:Client() -- the client is in every server
local Token = Module:RegisterToken('MyTokenToCountServers')

Client:Login(Token)

function getServers()
  return #Client.guilds -- returns a table for server job ids
end

print(getServers())