Hi. I have a problem with the datastore and I would like to see how it is saved. It is called “towers” (DataStore:GetDataStore(“towers”)) and I save the data via SetAsync(). Can I print all asyncs and their tables? I tried a few things, usually it returned some instance whose documentation is strange or just “towers” or e.g. “420036201: table: 0xe8e4400751969348”. I would like to see e.g. [playerId] = {“one”,“two”} or something similar. Is this possible?
what do you mean by “all the asyncs”? If you are referring to player entries, they aren’t “asyncs”, “async” means asynchronous, which is code running on a different thread to other code.
To get all the entries, you can use DataStore:ListKeysAsync(), and then use GetAsync for each entry of each page. To print it out, it should format it correctly in studio where it doesn’t show table: 0x000000, but otherwise you can simply iterate over it.
I didn’t know what to call it so I called it asyncs. Here’s my code:
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("towers")
local keys = DataStore:ListKeysAsync()
for i,v in keys:GetCurrentPage() do
print(i)
print(v.KeyName)
end
Can I print not the name v but just v to see what’s written there? When I print v it says “Instance” in the console and when .KeyName I have the player id.
DataStoreKey.KeyName contains the key data was saved with, which is why you get the player’s id. You need to use DataStore:GetAsync() with the key name as a parameter. Be careful of rate limiting!
DataStore:GetAsync(DataStoreKey.KeyName)
Don’t forget pcalls for data store methods where appropriate.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.