I’m making a ServerList system and as the title said GetHashMap Pages.IsFinished
returning bunch of false
before returning true
.
Server Script (ServerListHandler) ~Shorten
local Players = game:GetService("Players")
local MS = game:GetService("MessagingService")
local RS = game:GetService("ReplicatedStorage")
local SSS = game:GetService("ServerScriptService")
local RE, RF = RS.RemoteEvents.ServerRE, RS.RemoteFunctions.ServerRF
local ServerListManager = require(SSS.Modules.ServerListManager)
function UpdateServer()
ServerListManager:UpdateServer()
end
Players.PlayerAdded:Connect(UpdateServer)
Players.PlayerRemoving:Connect(UpdateServer)
UpdateServer()
print(game.JobId)
local Entries = ServerListManager:GetServers()
for i, entry in ipairs(Entries) do
print(i, entry.key)
for _, Id in ipairs(entry.value) do
print(Id)
end
end
Server Module-Script (ServerListManager) ~Shorten
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local MS = game:GetService("MessagingService")
local MSS = game:GetService("MemoryStoreService")
local ServerList = MSS:GetHashMap("ServerList")
local API = {}
local Expiration = 86400
local MaxListRetrieval = 30
function ReadPagesRecursive(Pages, Results)
print(Pages.IsFinished)
Results = Results or {}
-- Get the current page's data
for _, entry in ipairs(Pages:GetCurrentPage()) do
table.insert(Results, entry)
end
-- If there's another page, recurse
if Pages.IsFinished == false then
Pages:AdvanceToNextPageAsync()
return ReadPagesRecursive(Pages, Results)
else
return Results
end
end
function API:UpdateServer()
if RunService:IsStudio() then warn("game is running on studio") return end
local Data = {}
if #Players:GetPlayers() < 1 then
Players.PlayerAdded:Wait()
end
for _, Player in ipairs(Players:GetPlayers()) do
table.insert(Data, Player.UserId)
end
local Success, Data = DataMethods("SetAsync", game.JobId, Data, Expiration)
if Success then
MS:PublishAsync("ServerList", game.JobId)
end
end
function API:GetServers()
local Success, Pages = pcall(ServerList.ListItemsAsync, ServerList, MaxListRetrieval)
if Success then
return ReadPagesRecursive(Pages)
end
return nil
end
return API
the print is inside the ReadPagesRecursive
function.
As you can see in the image above, I only have 1 entry which is my server that I added into the map yet I have a bunch of false before it return the first entry.
Initially I thought maybe Pages is just returning cache values which it shouldn’t so I tested it again by commenting out ServerListManager:UpdateServer()
so that it doesn’t add
anything into the HashMap and same thing happen as you can see in the image below.
There isn’t any entry in the map so it should return true by default, I also tried changing local MaxListRetrieval = 30
to 1 to see if there’s any different but it returns the same result. I can assure that there isn’t any other script calling any of the functions above as I’m still on the testing phase.
Expected behavior
The behavior I’m expecting is that it should return true if there is no entry left in the hashmap pages.
A private message is associated with this bug report