Ordered Data Stores instead of Normal ones

So, as the title says. Is it possible to use Ordered Data Stores instead of Normal ones for saving data? Just wondering.

Yes, but why would you do that? Ordered Data Stores are mainly used for listed things like leaderboards etc

Because when I’m using a normal DataStore to save ingame points using the Roblox leaderstats system.

Code that saves the ingame points:

local DataStoreService = game:GetService('DataStoreService')

local KnobData = DataStoreService:GetDataStore("KnobDatas")
local DeathData = DataStoreService:GetDataStore("DeathDatas")

local Players = game.Players

Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new('Folder', player)
	leaderstats.Name = "leaderstats"
	
	local knobsvalue = Instance.new('NumberValue', leaderstats)
	knobsvalue.Value = 0
	knobsvalue.Name = "knobs"
	
	local deaths = Instance.new('NumberValue', leaderstats)
	deaths.Value = 0
	deaths.Name = "deaths"

	local data1
	local data2
	
	local yes, nomsg = pcall(function()
		data1 = KnobData:GetAsync(player.Name)
		data2 = DeathData:GetAsync(player.Name)
	end)
	
	if not yes then
		error(nomsg)
	end
	
	knobsvalue.Value = data1
	deaths.Value = data2
	
	print(data2)
	print(data1)
end)

Players.PlayerRemoving:Connect(function(player)
	KnobData:SetAsync(player.Name, player.leaderstats.knobs.Value)
	DeathData:SetAsync(player.Name, player.leaderstats.deaths.Value)
end)

And I have a code that displays the things on a Ordered Datastore leaderboard.
But, it won’t display the players data. I have to do something like this myself:

OrderedDataStoreThing:SetAsync("Key Name", 500)

And the key name can be anything. Which makes my leaderboard code useless and not working as intended.
Here’s the code for the leaderboard just incase:

local DatastoreService = game:GetService('DataStoreService')

local OrderedData1 = DatastoreService:GetOrderedDataStore("KnobDatas")
local OrderedData2 = DatastoreService:GetOrderedDataStore("DeathDatas")

local isAscending = false
local pagesize = 20

local SpecialColors = {
	[1] = Color3.fromRGB(0, 170, 255);
	[2] = Color3.fromRGB(255, 125, 39);
	[3] = Color3.fromRGB(255, 163, 135)
}

local pagething = OrderedData1:GetSortedAsync(isAscending, pagesize)

local SetAsync = OrderedData1.SetAsync
local Book = pagething:GetCurrentPage()

local PageThing2 = OrderedData2:GetSortedAsync(isAscending, pagesize)
local Book2 = PageThing2:GetCurrentPage()

-- Ranking (Knobs)
for rank, val in ipairs(Book) do
	
	local PlayerRank = script.Parent.SurfaceGui.KnobsMomento.Frame:Clone()
	
	for i = 1,#SpecialColors do
		
		if rank == i then
			
			PlayerRank.BackgroundColor3 = SpecialColors[i]
			
		end
	end
	
	PlayerRank.NameThing.Text = val.key
	PlayerRank.ValueAmount.Text = val.value
	PlayerRank.NumberBro.Text = "#"..rank
	PlayerRank.Visible = true
	PlayerRank.Name = val.key.."_"..rank
			
	PlayerRank.Parent = script.Parent.SurfaceGui.KnobsMomento
end

-- Ranking (Deaths)

for rank, val in ipairs(Book2) do

	local PlayerRank = script.Parent.SurfaceGui.DeathsMomento.Frame:Clone()

	for i = 1,#SpecialColors do

		if rank == i then

			PlayerRank.BackgroundColor3 = SpecialColors[i]

		end
	end

	PlayerRank.NameThing.Text = val.key
	PlayerRank.ValueAmount.Text = val.value
	PlayerRank.NumberBro.Text = "#"..rank
	PlayerRank.Visible = true
	PlayerRank.Name = val.key.."_"..rank

	PlayerRank.Parent = script.Parent.SurfaceGui.DeathsMomento
end

Sorry if this is too confusing.

This is unrelated to your problem, but you shouldn’t be using the Player’s name as the DataStore key; If the player changes their username, they will lose all of their data (You should be using their UserId instead).

1 Like

Hmm, didn’t think of that. Thanks for telling me

Nevermind, I just wasn’t refreshing the leaderboard. That’s why it wasnt showing up

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