API:Class/OrderedDataStore

Server only:This object is server-side only! You should use a Script instead of a LocalScript when using it.
Filtered-inheritance mode: While this class technically inherits all Instance class members, some (if not all) have been hidden because they serve no purpose for this object.

ExplorerImageIndex69.pngOrderedDataStore : ExplorerImageIndex69.pngGlobalDataStore : Object Icon.pngInstance

OrderedDataStore is a type of DataStore where the value must be an integer (positive number). This is done in order to create a way to easily order key/value pairs, making it suitable for leaderboard related scripting where you are required to order large amounts of data efficiently. For example, you can write a script that shows the top 100 high scores in your game.

Functions

Functions [toggle]

Inherited from ExplorerImageIndex69.pngGlobalDataStore:
RBXScriptConnectionOnUpdate ( string key, function(Variant) callback )

Sets callback as a function to be executed any time the value associated with key is changed. It is important to disconnect the connection when the subscription to the key is no longer needed.

|RMD member="API:Class/GlobalDataStore/OnUpdate"|Sets callback as a function to be executed any time the value associated with key is changed. It is important to disconnect the connection when the subscription to the key is no longer needed.|/RMD|
OnUpdate ( string key, function(Variant) callback )
Sets callback as a function to be executed any time the value associated with key is changed. It is important to disconnect the connection when the subscription to the key is no longer needed.

YieldFunctions

YieldFunctions [toggle]

DataStorePagesGetSortedAsync ( bool ascending, int pagesize, int minValue = nil, int maxValue = nil )

Returns a DataStorePages object. The length of each page is determined by pageSize, and the order is determined by isAscending. minValue and maxValue are optional parameters which will filter the result. See this article for a good explanation of using this. You can not use this too often, as there is a limit on the usage of this method.

|RMD member="API:Class/OrderedDataStore/GetSortedAsync"|Returns a DataStorePages object. The length of each page is determined by pageSize, and the order is determined by isAscending. minValue and maxValue are optional parameters which will filter the result. See this article for a good explanation of using this. You can not use this too often, as there is a limit on the usage of this method.|/RMD|
GetSortedAsync ( bool ascending, int pagesize, int minValue = nil, int maxValue = nil )
Returns a DataStorePages object. The length of each page is determined by pageSize, and the order is determined by isAscending. minValue and maxValue are optional parameters which will filter the result. See this article for a good explanation of using this. You can not use this too often, as there is a limit on the usage of this method.
Inherited from ExplorerImageIndex69.pngGlobalDataStore:
VariantGetAsync ( string key )

Returns the value of the entry in the DataStore with the given key.

|RMD member="API:Class/GlobalDataStore/GetAsync"|Returns the value of the entry in the DataStore with the given key.|/RMD|
VariantIncrementAsync ( string key, int delta = 1 )

Increments the value of a particular key and returns the incremented value.

|RMD member="API:Class/GlobalDataStore/IncrementAsync"|Increments the value of a particular key and returns the incremented value.|/RMD|
voidSetAsync ( string key, Variant value )

Sets the value of the key. This overwrites any existing data stored in the key.

|RMD member="API:Class/GlobalDataStore/SetAsync"|Sets the value of the key. This overwrites any existing data stored in the key.|/RMD|
VariantUpdateAsync ( string key, function<Variant>(Variant) transformFunction )

Retrieves the value of the key from the website, and updates it with a new value.

|RMD member="API:Class/GlobalDataStore/UpdateAsync"|Retrieves the value of the key from the website, and updates it with a new value.|/RMD|
Returns the value of the entry in the DataStore with the given key.
IncrementAsync ( string key, int delta = 1 )
Increments the value of a particular key and returns the incremented value.
SetAsync ( string key, Variant value )
Sets the value of the key. This overwrites any existing data stored in the key.
UpdateAsync ( string key, function<Variant>(Variant) transformFunction )
Retrieves the value of the key from the website, and updates it with a new value.


|RMD member="API:Class/OrderedDataStore"|OrderedDataStore is a type of DataStore where the value must be an integer (positive number). This is done in order to create a way to easily order key/value pairs, making it suitable for leaderboard related scripting where you are required to order large amounts of data efficiently. For example, you can write a script that shows the top 100 high scores in your game. |/RMD|


Example

The below example would print out the top ten players with the most points in the game to the output.

local DataStoreService = game:GetService("DataStoreService")
local PointsODS = DataStoreService:GetOrderedDataStore("Points") 
 
function printTopTenPlayers()
    local isAscending = false
    local pageSize = 10
    local pages = PointsODS:GetSortedAsync(isAscending, pageSize)
    local topTen = pages:GetCurrentPage()
 
    --The data in topTen is stored with the index being the index in the page, then a table with two keys: "key" and "value".
    --data.key is the key in the OrderedDataStore and data.value is the value in the OrderedDataStore
    for i,data in ipairs(topTen) do
        local username = data.key --Don't use the username as the key, this is just as an example
        local points = data.value
        print(username .. " is ranked #" .. i .. " with " .. points .. "points")
    end
end