How to check how much People are in the other Server

How could i check from Server 1 how much Players are in Server 2 and send from Server 2 the reserve access key? And where do i need pcall?

You can create a common MemoryStore accessed by all servers, where you will be able to register the OnLine Status of each player (true in PlayerAdded and false in PlayerRemoving).

1 Like

I read about that in the Roblox Wikipedia but i have a Question, i need to name the Queue like:

queue:MemoryStoreService:GetQueue("Queue1", 30)

But what happens if the same queue created with the same name? Like Queue1 again?

Don’t use queues, use Sorted Maps, which behaves exactly like a DataStore.

Okay i read it but i dont see where it stands how i could receive it, how could Server2 receive the MemoryStore and send the Players Value in the Server1 back?

Have you ever used DataStore? Do you know how it works?

Never used it


First, you need to understand how DataStore/MemoryStore works.
When you know, you can follow the idea below:


Think firstly about an online table/dictionary of players.
Inside the PlayerAdded function, you will add the player who joins the server in this table.

UsersOnline[Player.UserId]=true

Within the PlayerRemoving function, you will remove the player from this table.

UsersOnline[Player.UserId]=nil

But this table will be lost when the server is shut down.
So, for you to access player data from another server, you need to store this data somewhere.
It could be in a DataStore, but as the MemoryStore is faster and as in your case, you don’t need to leave the information of who is online in perpetuity, you can use MemoryStore.

To save this table in the MemoryStore, you first need to know the server Id, as you will have a unique table inside the MemoryStore with the players that are currently online, on each server.

To know the current Server Id:

So you will have a final table, with the server Id in the first dimension and the UserId of the Player that is online on this server as the second dimension.

Save this table to MemoryStore (use UpdateAsync to ensure the table is always updated regardless of which servers are writing to it).

And finally, to know how many users are online on a given server, do a GetAsync folder on this MemoryStore of online users and add the user records there.

1 Like

Thanks but i have one Question, u said:

But this table will be lost when the server is shut down.
So, for you to access player data from another server, you need to store this data somewhere.
It could be in a DataStore, but as the MemoryStore is faster and as in your case, you don’t need to leave the information of who is online in perpetuity, you can use MemoryStore.

But if the Server shut down, i dont need it or? Because i just need all of the active Servers to find their Players Count

1 Like

Think in a table like this:

 {
   ["ServerId1"] =  ▼  {
     [1234] = true,
     [4321] = true
   },
   ["ServerId2"] =  ▼  {
     [3333] = true
   },
   ["ServerId3"] =  ▼  {
     [1111] = true
   }
}

‘ServerId1, 2, 3’ are actually the number generated by JobId or other funcion above.
The numbers inside de ServerId are the UserIds of the users currently online on that server.

When a player joins a server, you add it to the table using the specific server id, and when the player leaves, you remove it.
When you want to know the number of users online on a specific server, just loop and sum the items inside the chosen ServerId.

So if i say

local queue = MemoryStoreService:GetQueue(“Queue1”)

am i getting the Queue or creating the Queue?