DataStorePages

Show Deprecated
Not Creatable
Not Replicated

A special type of Pages object whose pages contain key/value pairs from an OrderedDataStore. For this object, GetCurrentPage() returns an array of tables, each containing keys named key and value; these reflect the key/value pair data.

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

Properties

Events

Methods