GetSortedAsync in not a valid member of "DataStore" Leaderboard

  1. What do you want to achieve?

Simple Leaderboard that has datastores and shows most staff points across all servers and saves.

  1. What is the issue?

  1. What solutions have you tried so far? Tried just changing and messing with the datastore but still can’t figure out the problem? What could be leading towards this?

Code for Leaderstats :

local PointsStore = game:GetService("DataStoreService"):GetDataStore("Points")

game.Players.PlayerAdded:Connect(function(Player)

	local leaderstats = Instance.new("Folder", Player)
	leaderstats.Name = "leaderstats"
	
	local Rank = Instance.new("StringValue", leaderstats)
	Rank.Name = "Rank"
	Rank.Value = Player:GetRoleInGroup(8428801)
	
	local Points = Instance.new("IntValue", leaderstats)
	Points.Name = "Points"
	Points.Value = PointsStore:GetAsync("user_"..Player.userId) or 0
	
end)

game.Players.PlayerRemoving:Connect(function(Player)
	PointsStore:SetAsync("user_"..Player.UserId, Player.leaderstats.Points.Value)
end)


Code for Board :

-- [ SETTINGS ] --

local StatsName = "Points" -- Your stats name
local MaxItems = 25 -- Max number of items to be displayed on the leaderboard
local MinValueDisplay = 1 -- Any numbers lower than this will be excluded
local MaxValueDisplay = 10e15 -- (10 ^ 15) Any numbers higher than this will be excluded
local UpdateEvery = 80 -- (in seconds) How often the leaderboard has to update

-- [ LOCALS ] --

local PointsStore = game:GetService("DataStoreService"):GetDataStore(StatsName)
local SurfaceGui = script.Parent
local Sample = script.Template
local List = SurfaceGui.Frame.ScrollingFrame

-- [ GET ITEM FUNCTION ] --

local function GetItems()
	local Data = PointsStore:GetSortedAsync(false, MaxItems, MinValueDisplay, MaxValueDisplay)
	local TopPage = Data:GetCurrentPage()

	List.Nothing.Visible = #TopPage == 0 and true or false

	for i, v in ipairs(TopPage) do
		local UserId = v.key
		local Value = v.value
		local Username = "[Not Available]"
		local Color = Color3.fromRGB(38, 50, 56)

		local Success, Error = pcall(function()
			Username = game.Players:GetNameFromUserIdAsync(UserId)
		end)

		if i == 1 then
			Color = Color3.fromRGB(255, 215, 0)
		elseif i == 2 then
			Color = Color3.fromRGB(192, 192, 192)
		elseif i == 3 then
			Color = Color3.fromRGB(205, 127, 50)
		end

		local Item = Sample:Clone()
		Item.Name = Username
		Item.LayoutOrder = i
		Item.Points.TextColor3 = Color
		Item.Points.Text = i
		Item.Player.Text = Username
		Item.Rank.Text = Value
		Item.Parent = List
	end
end

-- [ USING BOARD FUNCTION ] --

while true do
	for i, v in pairs(game.Players:GetPlayers()) do
		local Stats = v.leaderstats:WaitForChild(StatsName).Value
		if Stats then
			pcall(function()
				PointsStore:UpdateAsync(v.UserId, function(Value)
					return tonumber(Stats)
				end)
			end)
		end
	end
	
	GetItems()

	wait()

	List.CanvasSize = UDim2.new(0, 0, 0, List.UIListLayout.AbsoluteContentSize.Y + 35)
	wait(UpdateEvery)
end


Why isn’t it getting the datastore?

GetSortedAsync is a function from Ordered Data Stores. You are currently using :GetDataStore which is getting the normal datastore. Instead, use :GetOrderedDataStore

3 Likes