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
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.
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()