Question about datastores and if I can look through em like this

So when it comes to datastores and saving stuff all the data is saved on a list

So basically I was wondering if when you use:

datastore:SetAsync(data)

is what I just saved at the bottom of the list of data in said datastore?


Cause I want to make it so I have a function so when you trigger it it gets the newest data saved to the datastore, when I really think about it I doubt thats how it works and it that is true how can I make it so I have a function so when you trigger it it gets the newest data saved to the datastore?

Thanks!

1 Like

you need a key

SetAsync(masterKey, data)

in your case, you could just use some sort of UTC timestamp as the key or provide it in the dataset itself.

as a pseudo example, i would probably do something like this but there could also be easier ways depending on the context… also dont forget to utilize things like pcall.

--server script, don't copy and paste.

local function getTimestamp()
    return os.date("!%Y-%m-%dT%H:%M:%SZ")
end

local masterKey = "myKey"

local data = DS:GetAsync(masterKey) 

data[getTimestamp()] = "blah"

DS:SetASync(masterKey, data)

and then you can easily go through “data” to see which entry inside is the latest one.

Well yes but theres a thing that allows you to get the stuff in a list I think its like datastore:GetAsyncsInOrderedList() or something

This is for an orderedDataStore, and it is :GetSortedAsync(). Just use :GetOrderedDataStore instead of :GetDataStore.

1 Like

So from the look of it(And actually using it).
Using GetOrdedDatastore() doesnt allow me to loop through the items it just gets the datastore in order and I am still unable to loop through the items with out using :GetSortedAsync(). At least thats what I can tell from the document

No way you gave urself the solution??

Oh sorry! Miss click!. My bad man

1 Like

All good, good luck with your game!

1 Like

Hmm do you know of a way to loop through regular datastores asyncs? I need to loop through the data with out using an OrderedDatastore cause they can only save numbers

You don’t loop through them, you use :GetAsync() and :SetAsync() with a key, usually the player’s userid. Please make a new post if you are stuck, also read up on the datastore’s documentation.

Yes I know but I need to well get them and basically loop through them as GetOrderedAsync works. Not that I think about it I can just save there titles to a datastore table and then loop through that

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