Is it safe to transfer all data inside a DataStore into an OrderedDataStore?

Hello,
My game blew up not too long ago so I decided to add donation buttons and make a bit of profit. I really rushed that update, which ended up in me committing a huge and very embarrassing mistake. I saved the amount of robux donated by the players inside a DataStore instead of an OrderedDataStore, which is problematic for the donation board that I’m about to create.
Of course, my first thought was “Can’t I just transfer all the data with a simple for loop?” Something like:

for i = 1,10000000000 do
    local bobux = DataStore:GetAsync(i)
    if bobux then
        OrderedDataStore:SetAsync(i,bobux)
    end
end --all of that with pcall() of course.

But how safe is that? It sounds very risky, and the huge number looks very scary. What if a big problem happens and I don’t know about it?
The other obvious possible solution is to transfer the data when the player joins the game. The obvious issue is that players who never join the game again will not get their name into the board, no matter how much they have donated. I will only do that if there is no better solution.
I don’t really know what I should do, can anyone help please?

Roblox Studio will crash and if you add task.wait() at the end it will take forever

2 Likes
for i = 1,10000000000 do
    local bobux = DataStore:GetAsync(i)
    if bobux then
        OrderedDataStore:SetAsync(i,bobux)
    end
end --all of that with pcall() of course.

This would absolutely cause your game to have a meltdown, so don’t do that.

Instead, create a separate OrderedDataStore, that saves once using :SetAsync() when the player leaves for each ordered value.

You shouldn’t have your main data saved in an orderdatastore using :SetAsync with no retrylogic anyway.

Create a separate store for the ordered data, make it link in to the normal data, job done, bobs your uncle.

2 Likes

Issue is it would very likely crash and also if it’s a large game it’s gonna take such a long time due to rate limiting.

Your best bet would be to do what @Zek4ry said about when a player leaves the game it gets from the normal one and puts it into a ordered one. Only issue with that is if the user never joins the game they will not get it so I would just make an annoucement or smthing about it.

2 Likes

https://developer.roblox.com/en-us/api-reference/function/DataStore/ListKeysAsync
You can use ListKeysAsync to get a list of a datastore’s keys, you can then retrieve the values associated with those keys and assign them to an ordered datastore.

2 Likes

Yea I know that but there would still be an issue of the rate limiting cuz you would need to go through lots if you have lots like what it seems in this post so best bet would be to do what me and @Zek4ry said.

If there was no rate limit you could use the OpenCloud API for datstore and do a system like that but if there are lots of people in the datastore having to wait after a few for the rate limit would be a pain tbh.

A million keys (I assume the actual amount is less than this) would only take roughly ~11.5 days to retrieve the values of, this is a task that can be performed in the background in a fresh studio window.

I mean you have just proved my point. It would be a nightmare to do. It would also take longer cuz you have the rate limit to remove the entry and then create a new entry.

Sure it would be possible but most people either don’t want to keep there desktop on overnight for up to 11.5 days. Also you have the issue of how if there is any sort of issue you may not know about it.

if you really wanted to do this best bet would be to get a cloud server and upload some code which will do it but tbh it’s still really not massively a good idea. Also if there are any mistakes u have lost that data.

you have the rate limit to collected these keys

There isn’t a rate limit when retrieving the keys, a request to ListKeysAsync returns a single ‘DataStoreKeyPages’ object that contains all of the queried datastore’s defined keys.

but also then the rate limit to remove the entry and

You don’t need to remove the existing data.

desktop on overnight for up to 11.5 days.

The task can be split up into smaller sub-tasks.

if you really wanted to do this best bet would be to get a cloud server and upload some code which will do it but tbh it’s still really not massively a good idea.

I wouldn’t advise using a third party data storage system, they’re typically less robust in comparison to the ‘DataStoreService’ Roblox provides.

I never said that they should use a third party data storage system? The Open Cloud is the Roblox system for API’s (they hope to transfer the web API’s later but for now they have place upload, datastore and messaging service API).

would be to get a cloud server and upload some code which will do it but tbh

You didn’t specify a particular cloud server here you just mentioned ‘a cloud server’ (there are many third party sites that provide a cloud service). You also ignored all of my other points.

Why would it get flagged? I am just saying if the user or you or anyone want to check out DigitalOcean u get some credits u can try it with. I don’t know what rule it breaks?

I’m not sure how to use that.
Would something like that work?

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("Donations") 
local OrderedDataStore = DataStoreService:GetOrderedDataStore("Donations") 
local Success, Pages = pcall(function()     
    return DataStore:ListKeysAsync()
end) 
if not Success then 
    warn("Timeout") 
    return 
end 
while task.wait(3) do          
    local Items = Pages:GetCurrentPage()          
    for _, Data in ipairs(Items) do                            
        local Key = Data.KeyName       
        local Value = Data.Value
        if Value then           
            OrderedDataStore:SetAsync(Key,Value)
        end                  
        task.wait(3)              
    end          
    if Pages.IsFinished then 
        break 
    else 
        Pages:AdvanceToNextPageAsync() 
    end      
end