I’m trying to develop a DataStore system able to save and load player data using folders and values as seen in the uploaded image. This way I can easily store player inventories, items, stats, etc.
I’ve been able to get close however, I want it to be modular, to where I could hypothetically have 5 folders inside each other and still have the system work.
I don’t expect someone to complete code this out for me, I just simply want to hear your ideas on how you would solve this problem.
Convert the PlayerData folder into a table, then encode the table using HttpService:JSONEncode(table). Then save it into the datastore.
To get the data, just :GetAsync it and then use HttpService:JSONDecode() on it. Then, loop through the table and create a table and object value for each of the objects inside.
I apologize I should have clarified that converting the folder and all of its contents, potentially being children of children of children, etc, into a table is my main concern.
I don’t see why this wouldn’t be possible, if you already have a system for saving values inside a the folder, all you need to check while looping through values of the first folder is if there is another folder inside.
function SaveFolder(Folder)
for i, v in pairs(Folder:GetChildren()) do
if v:IsA("Folder") then
SaveFolder(Folder)
else
-- Save Process of other values
end
end
end
If you are wondering how to apply the saving part to the folder, look at this code, I posted on this post. It’s a little bit outdated, now I usually put everything in the folder into a table and save it via. HttpService, but this works perfectly fine as well.