Getting Diffrent Values through GetOrderedDataStore

Hello everyone and I am making a leaderboard. I used a youtubers base script and modified it to my board and etc. In my leaderboard I want to have wins, loses, and absolute wins (ABSW). The problem I am running into is that I do not know how to get multiple values for my leaderboard. So I know how to get something like the wins, in the code.

-- [ SETTINGS ] --

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

-- [ END SETTINGS ] --

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard_" .. StatsName)
local SurfaceGui = workspace.Leaderboard.SurfaceGui
local Background = SurfaceGui.Background
local PlayerDisplay = SurfaceGui.Template

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

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

		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 = PlayerDisplay:Clone()
		Item.Name = Username
		Item.LayoutOrder = i
		Item.Number.Number.TextColor3 = Color
		Item.Number.Number.Text = i
		Item.PlrName.PlrName.Text = Username
		Item.PlrName.PlrName.TextColor3 = Color
		Item.Wins.Wins.Text = Value
	--	Item.Loses.Loses.Text = Loses
	--	Item.ABSW.ABSW.Text = ABSW
		Item.Parent = Background
		Item.Visible = true
	end
end

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

	for i, v in pairs(Background:GetChildren()) do
		if v:IsA("Frame") then
			v:Destroy()
		end
	end

	GetItems()

	wait()
	wait(UpdateEvery)
end

This works, but I want 3 different values. Right now, v only = one value, which is wins. Is their a way I can pass multiple values, and these values would be number of wins loses and ABSW

image

No, unfortunately doing :GetOrderedAsync() returns the top/bottom (whichever you choose) of each data store, regardless of the key. You’d have to use multiple OrderedDatastores.

So Wins has to be one DS, Loses has to be a different DS, and ABSW has to be another DS.

1 Like