Advanced DataStore system help

Greetings,

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.

list

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.

Thanks!

1 Like

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.

Loop through them using a for loop.

local mainFolder = path.PlayerData
local datatable = {
	Inventory = {
		Info = {
			CurHotbarSlots
		},
		Tools = {}
	},
	Stats = {
		Experience,
		Level,
		Rebirths,
		Shards	
	}
}

datatable.Inventory.Info.CurHotbarSlots = mainFolder.Inventory.Info.CurHotbarSlots.Value
datatable.Stats.Experience = mainFolder.Stats.Experience.Value
datatable.Stats.Level = mainFolder.Stats.Level.Value
datatable.Stats.Rebirths = mainFolder.Stats.Rebirths.Value
datatable.Stats.Shards= mainFolder.Stats.Shards.Value
for _, tool in pairs(mainFolder.Inventory.Tools:GetChildren()) do
	table.insert(datatable.Inventory.Tools,  tool.Name)
end

-- then you save it

Thank you, I suspected this would most likely be the solution, however, I’m pretty bad with tables in Lua so I thought I’d ask here for some advice

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.