OrderedDataStore error

Hey, I’m trying to create a global leaderboard for my game using an OrderedDataStore. The problem is that i get an error: ‘key is not a valid member of DataStorePages “Instance”’. What does this mean? Here’s the code if it helps:

local data = orderedPointsData:GetSortedAsync(false, 10)
local pointsPage = data:GetCurrentPage()

local userNamePoints = game:GetService("Players"):GetNameFromUserIdAsync(data.key)
-- error on this line ^

Thanks

image
This is an example of what the variable pointsPage holds. Since there are multiple keys with their own tables, you will need a for loop to loop through these tables to get the Usernames of these users. Here’s an example:

local data = orderedPointsData:GetSortedAsync(false, 10)
local pointsPage = data:GetCurrentPage()

for i,v  in ipairs(pointsPage) do
    local userNamePoints = game:GetService("Players"):GetNameFromUserIdAsync(v.key)
    print(userNamePoints)
    -- Other code...
end

i have done what you have said and it still prints the same error… Why is that?

local data = orderedPointsData:GetSortedAsync(false, 10)
local pointsPage = data:GetCurrentPage()
		
for i, v in ipairs(pointsPage) do
	local userNamePoints = game:GetService("Players"):GetNameFromUserIdAsync(v.key)
	local pointsValue = v.value
end

oh wait, i just saw that it was another part of the script that was doing that second error… Thanks for helping!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.