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