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 make this work with data store without changing to ordered data store?

I want to make a top players leaderboard gui script, but this only works with ordered data store, my game is using normal data stores and I dont want to change to ordered data store because I am not sure if it will reset all stats.

Stat = "Robux"

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


function updateBoard(board, data)
	for k,v in pairs(data) do
		local pos = k
		local name = v.key
		local score = v.value
		local nametextbox = script.Parent.Background.Top:FindFirstChild("Name" .. pos)
		nametextbox.Text = name
		local scoretextbox = script.Parent.Background.Top:FindFirstChild("Score" .. pos)
		scoretextbox.Text = score
	end	
end

while true do
	local pages = DataStore:GetSortedAsync(false, 10)
	local data = pages:GetCurrentPage()
	updateBoard(script.Parent.Background.Top, data)
	if not pages.IsFinished then
		pages:AdvanceToNextPageAsync()
		data = pages:GetCurrentPage()
	end
	wait(30)
end

2 answers

You can't, normal DataStores don't have the GetSortedAsync YieldFunction. This is what makes them different.

What you can do is save all data from now on in an OrderedDataStore (and get old data from the old DataStore if nothing was saved to the new OrderedDataStore yet) and manipulate your scoreboard on that. Unfortunetaly it will only take the data saved to the OrderedDataStore and not the old data saved to the normal DataStore.

You cannot do this in a way that isn't very hackish. The only way I could think of will just make the game very unstable as the game will have a higher chance of breaking due to datastore limits.

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