OrderedDataStore

Show Deprecated
Not Creatable
Not Replicated

A OrderedDataStore is essentially a GlobalDataStore with the exception that stored values must be positive integers. It exposes a method GetSortedAsync() which allows inspection of the entries in sorted order using a DataStorePages object.

See Data Stores for an overview on using ordered data stores.

Code Samples

OrderedDataStore Basics

1local DataStoreService = game:GetService("DataStoreService")
2local pointsStore = DataStoreService:GetOrderedDataStore("Points")
3
4local function printTopTenPlayers()
5 local isAscending = false
6 local pageSize = 10
7 local pages = pointsStore:GetSortedAsync(isAscending, pageSize)
8 local topTen = pages:GetCurrentPage()
9
10 -- The data in 'topTen' is stored with the index being the index on the page
11 -- For each item, 'data.key' is the key in the OrderedDataStore and 'data.value' is the value
12 for rank, data in ipairs(topTen) do
13 local name = data.key
14 local points = data.value
15 print(name .. " is ranked #" .. rank .. " with " .. points .. "points")
16 end
17
18 -- Potentially load the next page...
19 --pages:AdvanceToNextPageAsync()
20end
21
22-- Create some data
23pointsStore:SetAsync("Alex", 55)
24pointsStore:SetAsync("Charley", 32)
25pointsStore:SetAsync("Sydney", 68)
26
27-- Display the top ten players
28printTopTenPlayers()

Summary

Properties

Events

Methods

GetSortedAsync(ascending: boolean, pagesize: number, minValue: Variant, maxValue: Variant): Instance  YIELDS

Returns a DataStorePages object.

Properties

Events

Methods

GetSortedAsync

Yields

Returns a DataStorePages object. The sort order is determined by ascending, the length of each page by pageSize, and minValue/maxValue are optional parameters which filter the results.

If this function throws an error, see Data Stores for descriptions of the error codes.

Parameters

ascending: boolean

A boolean indicating whether the returned data pages are in ascending order.

pagesize: number

The length of each page.

minValue: Variant

Optional parameter. If set, data pages with a value less than than minValue will be excluded.

maxValue: Variant

Optional parameter. If set, data pages with a value greater than maxValue will be excluded.


Returns

A sorted DataStorePages object based on the provided arguments.