LiveServersService - Fetch running servers with simple code!

Introducing LiveServersService!

LiveServersService (hereafter referred to as LSS) is a simple module (written in under 200 lines lol) that can help you fetch running servers by writing just a few lines of code!

Installation

Roblox Marketplace

Why do I need this?

LSS might come in handy in some cases, such as when you want to make a server list for players to pick another server to join when they found themselves in a high-ping server.

Example Code

local LSS = require(path.to.LiveServersService)

LSS:Initiate()
LSS:AddToLiveServers()

while task.wait(60) do 
    _G.LiveServers = LSS:GetLiveServers() —>> Container does not necessarily have to be _G.
end

It’s just that simple!

API (only methods are there lol)

:Initiate()
Initiates memory data, in case it is the first time running. You must run this before calling any other methods.

:AddToLiveServers(refreshRate: number?)
Uploads the running server of the module (LSS) instance to the memory list. Any server must call this method before being able to be fetched by other servers as a running server. refreshRate (defaults to 300) decides for how long will it wait for between each server information update (as of now, only the number of players will be updated).

:RemoveFromLiveServers()
Removes the running server of the module (LSS) instance from the memory list. After calling this method, other servers will no longer be able to fetch the server as a running server. This method is automatically called when server is about to shutdown, after calling :Initiate().

:GetLiveServers(maxNo: number?, excludeSelf: boolean?, placeId: number?)
Fetches a maximum of maxNo (defaults to 20) currently running servers from the memory list. The returned table will be as following:

{
    [jobId_of_the_server_instance: string] = {
        NumberOfPlayers = number
        IsPrivateServer = boolean
        PlaceVersion = number
        Location = string -- Geographical location of the server, e.g. 'Tokyo, Japan'.
    }
}

If excludeSelf is nil or true and the running server of the module (LSS) is found to be included in the returned list, it is automatically removed from the list. However, note that the no. of items in the list would be [original number - 1] because of this. If placeId (defaults to the place’s Id) is given, it will return running servers of that place if that servers of that place has been added to the memory list.

Wanna donate?

This would help me a lot! Donate!

Lastly, rating the module would help a lot!

What do you think?
  • This module is awesome!
  • Somewhat solid, but I don’t think I would be using it.
  • Not really that good.
0 voters
5 Likes

Update 1.1

Fixed :AddToLiveServers() potentially yielding indefinitely.

it would be great if when calling getliveservers you could also get the jobid of that server, which would be very useful for server browsers and such to teleport to those servers directly :slight_smile:

1 Like

The table returned by :GetLiveServers() is actually a dictionary in which the key of each server info table is the JobId itself

1 Like

Update 1.2

:AddToLiveServers() no longer yields for refreshRate before checking whether is the server uploaded to the memory list to see if to unbind from updating cycle or not.

If I have secondary places, what I’ve already done on a secondary place is Initiate() and then AddToLiveServers(). But when I print GetLiveServers() on the main place, even though there’s a server running on the secondary place, it still always returns nil.

I already have some ideas about what could be causing this:

  • Either it’s not the same placeId,
  • Or it’s because I teleport players using TeleportToPrivateServer and I might need to change that.
  • i don’t use _G

Thanks for your reply !!

1 Like

As you described. Seems you haven’t Initiated LSS on main place. Maybe I am wrong

_G is not the essential container of the returned data, so you could just store it inside a variable.

Try these two solutions:

  • Try to run Initiate() first in your main place.
  • GetLiveServers() accepts PlaceId as its third parameter, if not given, it will default to the current PlaceId, which will return all running servers of your main place.

Let me know if that still doesn’t fix the issue!