How do i get the Value of a DataStore page?

Hey,

I Cant work out how to get the Value from a Page

Ive Gotten This far:

local DataStoreService = game:GetService("DataStoreService")

local listSuccess, pages = pcall(function()
	return DataStoreService:ListDataStoresAsync("PlayerStats_TestTwo")
end)

if listSuccess then
	
	while true do
	
		local data = pages:GetCurrentPage()

		for rank,stuff in pairs(data) do
			
			Player = Instance.new("StringValue")
			Player.Parent = game.Workspace.Players
			
			print(stuff.Value)
			
		end
		
		if pages.IsFinished then
			break
		end
		
		data:AdvanceToNextPageAsync()
	
	end
	
end

The print function breaks, All I know is that “stuff” is a Page Instance but I don’t know how to get the value out of it

Please help I cant find anything anywhere about this

EDIT: “PlayerStats_TestTwo” is PlayerID as the Key and a string as the Value but i cant get either of them from “stuff”

local DataStoreService = game:GetService("DataStoreService")
local players = workspace:WaitForChild("Players")

local pages
local succ, err = pcall(function()
	pages = DataStoreService:ListDataStoresAsync("PlayerStats_TestTwo")
end)

if succ then
	while task.wait() do
		local data = pages:GetCurrentPage()
		for index, value in pairs(data) do
			Player = Instance.new("StringValue")
			Player.Parent = players
		end
		if pages.IsFinished then
			break
		end
		data:AdvanceToNextPageAsync()
	end
end

The while true do might’ve caused a crash so I’ve added a yielding function call, also are you sure you want to create StringValue instances that frequently? You may also want to customise them.

It returns error:

Key is not a valid member of DataStoreInfo "Instance"

Same error as before :confused:

EDIT:

Just clocked I’m using the function ListDataStoresAsync which returns DataStoreInfo rather than the Pages that include keys and values.

Ive tried using GetOrderedDataStore Then GetSortedAsync but it returns 0 pages because the values are Strings. How can i get a list of data stores?

local DataStoreService = game:GetService("DataStoreService")
local players = workspace:WaitForChild("Players")

local pages
local succ, err = pcall(function()
	pages = DataStoreService:ListDataStoresAsync("PlayerStats_TestTwo")
end)

if succ then
	while task.wait() do
		local data = pages:GetCurrentPage()
		for index, value in pairs(data) do
			Player = Instance.new("StringValue")
			Player.Parent = players
		end
		if pages.IsFinished then
			break
		end
		data:AdvanceToNextPageAsync()
	end
end

I meant to remove those 2 print lines, try now.

Please read documentation, you don’t. ListDataStoresAsync is only intended to list DataStores with data in them. It returns a DataStoreListingPages with DataStoreInfo instances. DataStoreInfo, as it says on the tin, only provides information about a DataStore. Values aren’t associated with DataStores.

It seems like you were looking for ListKeysAsync though the above still applies here as well; it returns a DataStoreKeyPages with DataStoreKey instances. It does not provide the value of the key.

If you want the value of a key, you need to use GetAsync.