Is it possible to save numeric keys in a dictionary, as numbers, in DataStores?

If I save an array in DataStore, the keys are saved as numbers:

  • before SetAsync:

Teste = {123, 345, 567}

  • after SetAsync:

image


But if the keys, even being numbers, are from a dictionary, they are converted to strings:

  • before SetAsync:

Jogo.Teste = {[3] = 123, [4] = 345, [5]=567}

  • after SetAsync:

image

Is it possible to save numeric keys in a dictionary, like numbers and not strings, in DataStores?

Or you could convert them to numbers. Use tonumber(string) to convert the string.

1 Like

This is likely due to how either Lua or JSONs handle arrays. In both cases, arrays are typically unlabeled. Lua doesn’t have too much of an issue if you wanted to start an array at 3, but typical array functions wouldn’t work. With JSONs though, arrays need to start at 1 (using Lua), otherwise it will need to create a key to match. Keys are always strings in JSON format.

1 Like

I imagine you’re referring to converting keys AFTER GetAsync, right?
But my question was whether it’s possible to store these numeric dictionary keys as numbers in DataStore, not as strings.
But from the @JarodOfOrbiter explanation, this has to do with the behavior of JSON.

Well, why would you need to store it and access it before getting GetAsync. I’m pretty sure data stores use strings to save data.

1 Like