Hey devs,
I am currently a game which need a few datastores, until now, everything worked, but I have a few issues with one of the datastore :
My code :
local success, errorMessage = pcall(function()
local RANDOMDS = DS:GetDataStore("RANDOMDATASTORE")
RANDOMDS:SetAsync(821632518, 1)
print(RANDOMDS:GetAsync(821632518))
end)
if not success then
warn(errorMessage)
end
The issue is that the datastore is setting the data to “1 instance” instead of 1. At this point I am very confused, hope someone can help 
iirc, DataStore::GetAsync
returns a tuple now instead of just the value of the data. The “instance” portion is just the other returned value
1 Like
It’s just my userId to test the script.
local DSService = game:GetService("DataStoreService")
local DataStore = DSService:GetDataStore("RandomDS")
local res1
local res2
local succ, err = pcall(function()
res1 = DataStore:SetAsync(821632518, 1)
end)
if succ then
print(res1)
else
print(err)
end
local succ, err = pcall(function()
res2 = DataStore:GetAsync(821632518)
end)
if succ then
print(res2)
else
print(err)
end
As the above post stated, GetAsync() returns a tuple (2 or more separate values) however the first value returned is always the value associated with the specified key passed as an argument to the “GetAsync()” call.
FYI: DataStoreKeyInfo is the second thing being returned from GetAsync. print will tostring all its arguments so Instance is just what DataStoreKeyInfo is when represented as a string. Read GetAsync for a proper code sample on working with GetAsync*.
* I say this because I’m not a fan of creating more upvalues like the above code sample does. You can already declare your local variables and pcall your DataStore method in one line, you don’t need more variables to do it. Not sure where this pattern came from, but pretty unnecessary.
local success, value, keyInfo = pcall(function ()
return DataStore:GetAsync(key)
end)
2 Likes