Learn
Engine Class
MemoryStoreSortedMap
Not Creatable
Not Replicated

Summary
Methods
GetRangeAsync(direction: Enum.SortDirection,count: number,exclusiveLowerBound: Variant,exclusiveUpperBound: Variant):{any}
SetAsync(key: string,value: Variant,expiration: number,sortKey: Variant):boolean
UpdateAsync(key: string,transformFunction: function,expiration: number):Tuple
Inherited Members

API Reference
Methods
GetAsync
Yields
Capabilities: DataStore
MemoryStoreSortedMap:GetAsync(key:string):Tuple
Parameters
key:string
Returns

GetRangeAsync
Yields
Capabilities: DataStore
MemoryStoreSortedMap:GetRangeAsync(
direction:Enum.SortDirection, count:number, exclusiveLowerBound:Variant, exclusiveUpperBound:Variant
Parameters
count:number
exclusiveLowerBound:Variant
exclusiveUpperBound:Variant
Returns
Code Samples
Retrieving MemoryStore Keys
local MemoryStoreService = game:GetService("MemoryStoreService")
local myMap = MemoryStoreService:GetSortedMap("MySortedMap")
function printAllKeys(map)
-- the initial lower bound is nil which means to start from the very first item
local exclusiveLowerBound = nil
-- this loop continues until the end of the map is reached
while true do
-- get up to a hundred items starting from the current lower bound
local items = map:GetRangeAsync(Enum.SortDirection.Ascending, 100, exclusiveLowerBound)
for _, item in ipairs(items) do
print(item.key)
print(item.sortKey)
end
-- if the call returned less than a hundred items it means we've reached the end of the map
if #items < 100 then
break
end
-- the last retrieved key is the exclusive lower bound for the next iteration
exclusiveLowerBound = {}
exclusiveLowerBound["key"] = items[#items].key
exclusiveLowerBound["sortKey"] = items[#items].sortKey
end
end
printAllKeys(myMap)

GetSizeAsync
Yields
Capabilities: DataStore
MemoryStoreSortedMap:GetSizeAsync():number
Returns

RemoveAsync
Yields
Capabilities: DataStore
MemoryStoreSortedMap:RemoveAsync(key:string):()
Parameters
key:string
Returns
()

SetAsync
Yields
Capabilities: DataStore
MemoryStoreSortedMap:SetAsync(
key:string, value:Variant, expiration:number, sortKey:Variant
Parameters
key:string
value:Variant
expiration:number
sortKey:Variant
Returns

UpdateAsync
Yields
Capabilities: DataStore
MemoryStoreSortedMap:UpdateAsync(
key:string, transformFunction:function, expiration:number
Parameters
key:string
transformFunction:function
expiration:number
Returns
Code Samples
Updating a MemoryStore Sorted Map
local MemoryStoreService = game:GetService("MemoryStoreService")
local map = MemoryStoreService:GetSortedMap("Leaderboard")
local Players = game:GetService("Players")
function updateLeaderboard(itemKey, killsToAdd, deathsToAdd)
local success, newStats, newScore = pcall(function()
return map:UpdateAsync(itemKey, function(playerStats, playerScore)
playerStats = playerStats or { kills = 0, deaths = 0 }
playerStats.kills += killsToAdd
playerStats.deaths += deathsToAdd
if playerStats then
-- `playerScore` is the sortKey being used to sort items in the map
playerScore = playerStats.kills / math.max(playerStats.deaths, 1)
return playerStats, playerScore
end
return nil
end, 30)
end)
end
-- Add one kill to all players
for i, player in pairs(Players:GetPlayers()) do
updateLeaderboard(player.UserId, 1, 0)
end
-- Add 5 kills and 1 death to player with userId 12345
updateLeaderboard(12345, 5, 1)

©2026 Roblox Corporation. Roblox, the Roblox logo and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.