Messaging service or datastores?

Hi, I was making a server system and I ran into a doubt, should I use datastores to load servers or messaging service?

If I use messaging service:

  1. Is it “reliable”? Or can it fail a couple of times?

  2. What if a new player joins? Will they only “listen” to the new servers sent?

If I use datastores:

  1. There’s a limit for ordered datastores

  2. I will have to make a refresh button or refresh it every X time

2 Likes

Forgot to change the topic of the draft lol

What do you mean by loading servers?

https://developer.roblox.com/en-us/articles/memory-store

is also a 3rd option

but because I don’t know what your server system does I cant tell you what option is the best option for you

2 Likes

I’d recommend you MemoryStores - meant for storing dynamic data.
MessagingService is the worst choice - not too reliable and has a lot of limits.

a UI which displays the available global servers to join

I’m having some trouble right now, I was finding out what method was the best and I found out that memory stores are just like data stores but temporary, so I’ll open the topic again but explaining better:

I have a servers GUI, which will display the servers available (those servers use datastores even though they are temporary they get deleted on remove)

I want the GUI to update itself when a new server is created, but also retrieve all current servers if you just started playing, not just the new ones being created

My best guess is I’d use ordered datastores to get a list of servers and then get the DATASTORE key for each one in a for loop, and then once we have all servers currently running, get the new ones being made

There isn’t a function to get all active servers. The servers lists are made using messaging service. Each server sends its data and you update the frame with thst data for every player every x seconds

i didn’t mean that, I’ll use datastores because I need to do so, the way I’d get all currently running servers is by using ordered datastores and get async for every ordered datastore key, then subscribe to messaging service to receive new servers

Sorry but if you already know how to do it what are you asking?

I’m asking if there’s any better way to do it or more reliable than messaging service for example, but since the only other option is memory service (which is a datastore but temporal) then I will just stick to the same idea

MemoryStores allow you to get and save data with smaller delay so you can easily get a list of all the servers each 0.5 second.
It’s also easier to use than OrderedDataStores so your code will be more clean.

here is some code to get you started

local memoryStoreService = game:GetService("MemoryStoreService")
local sortedMap = memoryStoreService:GetSortedMap("Servers")
local serverList = {}
local updateRate = 1

local function UpdateServerList()
    local newServerList = {}
    local exclusiveLowerBound = nil
    while true do
        local success, value = pcall(sortedMap.GetRangeAsync, sortedMap, Enum.SortDirection.Ascending, 200, exclusiveLowerBound)
        if success == false then return end
        for i, data in ipairs(value) do newServerList[data.key] = data.value end
        if #items < 200 then break end
        exclusiveLowerBound = value[#value].key
    end
    serverList = newServerList
end

local function Loop()
    delay(updateRate, Loop)
    local success, value = pcall(sortedMap.SetAsync, sortedMap, game.JobId, #game.Players:GetPlayers(), updateRate + 1)
    UpdateServerList()
    print(serverList)
end

Loop()
1 Like

I appreciate your post, I didn’t need it but I will see it as a reference