Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I convert data store to ordered data store?

Along time ago I asked, "How would I use leaderboards with data stores." But people said I needed order data stores, but on the WIKI it says ordered datastores are just like datastores but it organizes your data. But it doesn't show how to make an ordered data store, it just shows the leaderboard, unless I'm not understanding it right, Please help!

local DataStore = game:GetService("DataStoreService"):GetDataStore("RobuxClicker2omgStats")


game.Players.PlayerAdded:connect(function(player)
	
	local stats = Instance.new("IntValue", player)
	stats.Name = "stats"
	
	
	local perclick = Instance.new("IntValue", stats)
	perclick.Name = "Per Click"
	perclick.Value = 1
	
	local persec = Instance.new("IntValue", stats)
	persec.Name = "Per Sec"
	persec.Value = 0
	
	local click1 = Instance.new("IntValue", stats)
	click1.Name = "Click 1"
	click1.Value = 0
	
	local click2 = Instance.new("IntValue", stats)
	click2.Name = "Click 2"
	click2.Value = 0
	
	local click3 = Instance.new("IntValue", stats)
	click3.Name = "Click 3"
	click3.Value = 0
	
	local click4 = Instance.new("IntValue", stats)
	click4.Name = "Click 4"
	click4.Value = 0
	
	local item1 = Instance.new("IntValue", stats)
	item1.Name = "Item 1"
	item1.Value = 0
	
	local item2 = Instance.new("IntValue", stats)
	item2.Name = "Item 2"
	item2.Value = 0
	
	local click5 = Instance.new("IntValue", stats)
	click5.Name = "Click 5"
	click5.Value = 0
	
	local click6 = Instance.new("IntValue", stats)
	click6.Name = "Click 6"
	click6.Value = 0
	
	local item3 = Instance.new("IntValue", stats)
	item3.Name = "Item 3"
	item3.Value = 0
	
	local item4 = Instance.new("IntValue", stats)
	item4.Name = "Item 4"
	item4.Value = 0
	
	local item5 = Instance.new("IntValue", stats)
	item5.Name = "Item 5"
	item5.Value = 0

	local item6 = Instance.new("IntValue", stats)
	item6.Name = "Item 6"
	item6.Value = 0
	
	local click7 = Instance.new("IntValue", stats)
	click7.Name = "Click 7"
	click7.Value = 0
	
	local click8 = Instance.new("IntValue", stats)
	click8.Name = "Click 8"
	click8.Value = 0


	local key = "player-"..player.userId
	
	local savedValues = DataStore:GetAsync(key)
	
	if savedValues then
		--Save format: {perclick, persec}
		perclick.Value = savedValues[1]
		persec.Value = savedValues[2]
		click1.Value = savedValues[3]
		click2.Value = savedValues[4]
		click3.Value = savedValues[5]
		click4.Value = savedValues[6]
		item1.Value = savedValues[7]
		item2.Value = savedValues[8]
		click5.Value = savedValues[9]
		click6.Value = savedValues[10]
		item3.Value = savedValues[11]
		item4.Value = savedValues[12]
		item5.Value = savedValues[13]
		item6.Value = savedValues[14]
		click7.Value = savedValues[15]
		click8.Value = savedValues[16]
	else 
		local valuesToSave = {perclick.Value, persec.Value, click1.Value, click2.Value, click3.Value, click4.Value, item1.Value, item2.Value, 
		click5.Value, click6.Value, item3.Value, item4.Value, item5.Value, item6.Value, click7.Value, click8.Value}
		DataStore:SetAsync(key, valuesToSave)		
	end
end)

Leaving Script

local DataStore = game:GetService("DataStoreService"):GetDataStore("RobuxClicker2omgStats")

game.Players.PlayerRemoving:connect(function(player)
	
	local key = "player-"..player.userId
	
	local valuesToSave = {player.stats["Per Click"].Value, player.stats["Per Sec"].Value, player.stats["Click 1"].Value, player.stats["Click 2"].Value, 
	player.stats["Click 3"].Value, player.stats["Click 4"].Value, player.stats["Item 1"].Value, player.stats["Item 2"].Value, player.stats["Click 5"].Value, 
	player.stats["Click 6"].Value, player.stats["Item 3"].Value, player.stats["Item 4"].Value, player.stats["Item 5"].Value, player.stats["Item 6"].Value
	, player.stats["Click 7"].Value, player.stats["Click 8"].Value}
	
	DataStore:SetAsync(key, valuesToSave)
end)

1 answer

You should only use an ordered data store when you want to get a list of top scores, from the wiki page:-

"OrderedDataStore is a type of DataStore where the value must be an integer (positive number). This is done in order to create a way to easily order key/value pairs, making it suitable for leaderboard related scripting where you are required to order large amounts of data efficiently. For example, you can write a script that shows the top 100 high scores in your game."

It is also possible to use both types of data stores note that the request limits apply as a whole and not individually per data store.

To get an OrderedDataStore simply use the function GetOrderedDataStore function that is in the DataStoreService

It works the same way as an global data store except it only allows positive integers and will error is any other type is passed.

Back to your question, you do not need to "convert" the data. It is possible to have the same data (must abide the format) in both data stores. You should only use an Ordered DataStore for ranking systems as they are inefficient because they only store integers which will require a lot of requests to get each piece od data.

I hope this helps.

This discussion is preserved as it was. New answers, comments, and votes are closed.