How would I go about datastoring a folder with children?

What do I want to achieve?
Basically, I have this 1 folder parented to the player once joined called “OwnedItems”, that folder holds everything you’ve bought from the in-game shop, I also want to use folders because it’s way easier to handle inventory systems that way.

What is the issue?
I basically do not know how to datastore a folder with descendants, I’ve looked up some more forums about it but yet again I can’t seem to understand / comprehend what they were doing, so if you would like to help me keep it simple and clear.

What solutions have I tried so far?
I’ve tried couple but they wouldn’t make sense as I was just messing around to see if I would have an outcome.

-- Upon joinining:

	local coinsData

	local successCoins, ErrorCoins = pcall(function()
		coinsData = game:GetService("DataStoreService"):GetDataStore("-"):GetAsync(player.UserId)
	end)

	if coinsData then
		coins.Value = coinsData
	else
		warn(ErrorCoins)
	end

-- Once changed

	coins.Changed:Connect(function()
		game:GetService("DataStoreService"):GetDataStore("-"):SetAsync(player.UserId, player.ValueStats.Coins.Value)
	end)

-- Upon leaving

	local coinsData

	local successCoins, ErrorCoins = pcall(function()
		coinsData = game:GetService("DataStoreService"):GetDataStore("-"):SetAsync(player.UserId, player.ValueStats.Coins.Value)
	end)

	if successCoins then
		
	else
		warn(ErrorCoins)
	end

I’m asking help to see if y’all can convert my datastore code into something that datastores folders descendants, If you need anything just reply down below, appreciate it.

Note: the datastore script I put out works just fine, but if you see an issue you can always inform me about it

Have a dictionary with the parent’s name and put its children’s names in it. You cannot store blob data (instances) in DataStores but instead storing their names in tables, and having a big replica of every item and folder in ServerStorage would do the trick.

1 Like

Explain it in simple words, cannot really understand what you just said.

You should only store item names in a DataStore, it can’t store instances. Have all items in ServerStorage and when a player joins just clone the items the player owns to their Player instance.

1 Like

And how would I do that, if you’re saying making seperate values for every single tool, that would be a drag, that’s why I wanted to know if I could datastore folders with children

I scripted an example of storing and using tables Data store saving script only saving 1 of the 3 values - #14 by Extrenious

Because datastores cannot store instances you serialize the instance by making a table and just storing the instance properties within the table

1 Like