How can I save a folder?

I’m trying to store my skins with a datastore; The skins are in a folder, but I’m not sure how I can save everything inside the folder and then load all the items in the folder back.

Here is my current script; I’m not sure if I’m saving them correctly and how can I load them into the skins folder?

	local Leaderstats ='Folder',Player)
	Leaderstats.Name = 'Leaderstats'
	local Skins ='Folder',Player)
	Skins.Name = 'Skins'
	local EquippedSkin ='StringValue',Leaderstats)
	EquippedSkin.Name = 'EquippedSkin'
	EquippedSkin.Value = DefaultSkin.Value
	local TeddyBucks ='IntValue')
	TeddyBucks.Parent = Leaderstats
	TeddyBucks.Name = 'TeddyBucks'
	TeddyBucks.Value = DefaultValue
	local Data = TeddyBucksStore:GetAsync(Player.UserId)
	local Data2 = SkinsStore:GetAsync(Player.UserId)
	if Data then
		TeddyBucks.Value = Data.Stats.TeddyBucks
	if Data2 then

	local SaveData = {Stats = {}}
	local SaveData2 = {Stats2 = {}}
	SaveData.Stats.TeddyBucks = Player.Leaderstats.TeddyBucks.Value
	for _, Skin in pairs(Players.Skins:GetChildren()) do
		SaveData2.Stats.Skins = Skin

How can I configure it with my current script? This also saves my coins too!

1 Like

You’ve got most of the systems setup already in the script, and from what I see you already attempted to fill out the SaveData2.Stats.Skins table in your datastore with the skins the player has.
To successfully store/reload the players stats, you would first likely need to modify the loop where you set the Stats.Skins table in two ways, as if I recall correctly you cannot store Instance’s in datastores.

You’re also setting Stats.Skins to an Object, and if i’m not mistaken you want Stats.Skins to be an array of objects that you can read from when you load all the player’s skins later. table.insert you may find is very useful for that purpose.

To load this data assuming Skins is an array, you could simply iterate over the datastore.Stats.Skins table and create based on the entries in it.

it also seems like for every skin in your table you are using SetAsync with the SaveData2 table. Beware of this, as it’s not the best practice and may lead to queuing of datastore requests or even requests being dropped if someone has many skins!

I hope this helped, and good luck on your script! :partying_face: