How to convert a table into instances and instances to table?

First of all, I know there’s a module out there to do this, however I would rather do it myself than rely on another users module for this.

Now, my question is if there is a simple way to convert a table into instances, and then back to a table? I don’t know where to begin but I’ve seen a couple of similar posts where they used recursive functions to loop through the table or children/descendants

Here’s what I’m talking about:

local Main = {
   Table1 = {
     Value1 = false,
   },
   Table2 = {
     Value2 = true,
   },
}

RobloxStudioBeta_2022-04-02_16-38-27

I’m planning on using this to convert a DataStore template to instances for every new user that joins the server, and storing their data there; and back to a table later on.

Any help is appreciated

Why must you use folders and value instances to store data in the first place? Couldn’t you just store them inside scripts and keep them there? If it’s so that different scripts can all access the same data, you can simply store it inside _G, shared, or modulescripts. Using the instance hierarchy to store data sounds unconventional and very impractical since the kinds of data you can store are limited as well as possible performance issues that might come into play.
Also, attributes can be used (and is often better) as an alternative to most instance values.

1 Like

Yeah, you’re right. I kind of made this post on a whim, but I went on and did some more testing and realized it would be better to store them in a table rather then convert them to instances. Bad habits die hard