PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

GetOrderedDataStore

This method returns an OrderedDataStore, similar to the way DataStoreService/GetDataStore|GetDataStore() does with GlobalDataStore|GlobalDataStores. Subsequent calls to this method with the same name/scope will return the same object.

Parameters

Name Type Default Description
global

Returns

Return Type Summary

Code Samples


OrderedDataStore Basics

This code sample demonstrates usage of an OrderedDataStore and pages.

local DataStoreService = game:GetService("DataStoreService")
local PointsODS = DataStoreService:GetOrderedDataStore("Points") 

local 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 on the page
	-- For each item, 'data.key' is the key in the OrderedDataStore and 'data.value' is the value
	for rank, data in ipairs(topTen) do
		local name = data.key
		local points = data.value
		print(data.key .. " is ranked #" .. rank .. " with " .. data.value .. "points")
	end

	-- Potentially load the next page...
	--pages:AdvanceToNextPageAsync()
end

-- Create some data
PointsODS:SetAsync("Alex", 55)
PointsODS:SetAsync("Charley", 32)
PointsODS:SetAsync("Sydney", 68)

-- Display the top ten players
printTopTenPlayers()