OrderedDataStores discard metadata without warning

Last week I deployed the back end for a new analytics tool for my game, only to realize upon finishing the front end this week that the back end hasn’t been saving anything at all, since it depends upon saving metadata to go along with users’ keys in an ordered datastore.

Ordered data stores don’t save metadata - this seems to be intended behavior, but I wasn’t aware of it at the time. It’s only mentioned one time in the documentation from what I can tell.

If you attempt to save metadata to an ordered datastore via UpdateAsync (and probably SetAsync as well), the metadata will be silently discarded with no warning to the developer. This behavior should be made much more clear so this doesn’t happen to other developers.

Thanks for the report! We’ll follow up when we have an update for you.

Hi @ChipioIndustries,
I’m from the Data Pod team and would like to investigate. Can you include a sample of your code so I can better understand what you mean by metadata you are trying to save but isn’t being saved?

1 Like

Sure!

local DataStoreService = game:GetService("DataStoreService")

local dataStore = DataStoreService:GetOrderedDataStore("MyOrderedDataStore")

dataStore:UpdateAsync("Player_1337", function(oldValue)
	local leaderboardScore = 8675309
	local metadata = {
		importantData = "this is important probably";
	}
	return leaderboardScore, {}, metadata
end)

local value, keyInfo = dataStore:GetAsync("Player_1337")

print(value) --> 8675309
print(keyInfo) --> nil
1 Like

Thank you for posting your code, and apologies for the delayed response.

We have updated the docs here, to indicate that ordered datastores don’t support metadata.

Looking at your code snippet, it appears that you’d like to build a leaderboard of sorts for your experience. This can be achieved using a few different approaches

  • A MemoryStores Sorted Map (using the Sort Key feature)
    • Player_1337 would be the key, the metadata would be the value and the score would be the sort key
    • This could have a max expiration of up to 45 days
    • To persistently, store this information, you could save this information to a standard data store upon player exit (which has metadata support)

A sorted map does have a restriction on the total number of items, and if your leaderboard is intended to be global and support more than 1M players, another alternative is to use:

  • A combination of standard and ordered datastores such that
    • The standard datastore would store the metadata for Player_1337
    • The ordered datastore would store the score for Player_1337

Hope this answer helps, happy creating! :slight_smile:

1 Like

Thanks for getting back to me! I wound up going with a version of the second suggestion and it’s been working well.

This is a good improvement, but I usually only read the API docs, not the guides. I’d recommend adding the warning to the GlobalDataStore:GetAsync function and the top of the OrderedDataStore page as well.

Also, I still think the best solution for this is to throw a warning when metadata is passed to the API on an OrderedDataStore. It would guarantee that the developer would catch the problem while not breaking any existing code.

2 Likes

Updated the API Docs for OrderedDataStore page - OrderedDataStore | Documentation - Roblox Creator Hub.

We will discuss throwing a warning in Studio itself so that it’s more obvious when using the API. Thanks for your feedback!

1 Like