Data Table Order Mix Up


do table orders get mixed up if you save them one way

and you load them in when you join a new server?

using data stores


A data store is, according to the official documentation, similar to a dictionary (key-value pairs). Considering this, you shouldn’t have to worry about the order in which the data is retrieved.
Though, to answer your question, I highly doubt that the order of key-value pairs would be mixed up between sessions.
If you are truly concerned about this, and you are just storing positive integers, you may consider using an Ordered Data Store.


I do not understand how this is an alternative solution or one that should be recommended to people. I don’t think anyone would want to store separate numbers into ordered datastores when you could just store them in one table in a regular datastore…

To answer the question in the first post:

  • If you are storing an array, like
    {"hello", "world", "this", "is", {1, 2, 3}, "an", "array"}
    Then you can be sure that when you load this again from datastores, every entry is still at the same index that you saved it at. Iterating over them in terms of for i = 1, #data do will have consistent ordering in the elements, since they are just stored as subsequent indices that increment from 1, before and after loading.
  • If you are storing things by string index, like
    { Test = {...}, Value = 2, Pets = {...}, Items = {...}, Message = "Hello!" }
    Then you can also be sure that when you load it, every entry is still at the same index, but if you iterate over that with a for ... in pairs(data) do loop, the ordering is not defined. So you might see the order in which the string keys are traversed to be different when you loop over them before saving and after loading.

Note: doing a pairs-loop over an array also has undefined ordering technically speaking, so make sure to do the for i = 1, #data do variant if you need consistent order of traversal.