When trying to save an array that doesn’t have the index/key 1
defined, the array’s keys turn to strings when retrieved using GetAsync.
Reproduction Steps:
Create a new experience and enable studio access to API Services
Run the following script/line using the Command Bar:
game:GetService("DataStoreService"):GetDataStore("SomeDataStore"):SetAsync("Key", {[2] = "a", [3] = "b"})
Now get the data back using GetAsync, also using the command bar:
print(game:GetService("DataStoreService"):GetDataStore("SomeDataStore"):GetAsync("Key"))
You’ll find that the indexes/keys of the array are now strings instead of numbers.
In addition, if that array does contain the key/index 1, but the array has a missing key-value pair inside it, in some cases, only a part of the array is stored.
Reproduction Steps:
Run the following script/line using the Command Bar:
--Notice how index/key 2 is missing, watch what happens when the data is retrieved:
game:GetService("DataStoreService"):GetDataStore("SomeDataStore"):SetAsync("Key", {[1] = "a", [3] = "b"})
Now get the data back using GetAsync, also using the command bar:
print(game:GetService("DataStoreService"):GetDataStore("SomeDataStore"):GetAsync("Key"))
Key/Index 3 is no longer in the array, for some reason.
I tried adding a 4th key to the array with a missing 2nd key/index. For some reason, it works in that case:
game:GetService("DataStoreService"):GetDataStore("SomeDataStore"):SetAsync("Key", {[1] = "a", [3] = "b", [4] = "c"})
print(game:GetService("DataStoreService"):GetDataStore("SomeDataStore"):GetAsync("Key"))
This behavior seems to be inconsistent. I couldn’t find any documentation on the above occurrences.
System information:
Expected behavior
I expect the array to be stored exactly like I stored it.
Which means, keys/indexes should still be numbers if index/key 1 is missing, and values shouldn’t be emitted from the array if the array has a missing key/index inside it.