How to save a folder with datastore

hello. I’ve been trying to save a pet folder with this script:

local datastore = game:GetService("DataStoreService")
local miranura = datastore:GetDataStore("MiRanura")

game.Players.PlayerAdded:Connect(function(player)
	local carpeta = player:WaitForChild("mascotas")
	local userid = player.UserId
	local mascotasList = {}
	for i , mascotas in pairs(player.mascotas:GetChildren()) do
		table.insert(mascotasList)
	local guardar =	miranura:SetAsync(player.UserId .. "mascotasguardadas", mascotasList)
			
		local mascotasguardadas = miranura:GetAsync(player.UserId .. "mascotasguardadas") or {}
			for i, character in pairs(mascotasguardadas) do
			if game.ReplicatedStorage:WaitForChild("Mascotas"):FindFirstChild(character) then
				game.ReplicatedStorage.CharactersFolder[character]:Clone().Parent = carpeta
			end
		end
	end

	
	
end)

if anyone knows how to help me thank you very much

basically just use getchildren on the folder and then encode it in a string or a table.

friend where? If you realize I already did it in the script or where do I have to put it please
Or how do I do it? I’m not very good

so uhh there is a function in datastore called :SetAsync() you know that I dont see it in your code but here is rough script idea

local Folder = -- the folder you want to get things from
local function SetData()
local tableofdata = {}
for i,v in pairs(Folder:GetChildren()) do
local data = {Color = v.Color, Material = v.Material, Position = v.Position}
tableofdata[v.Name] = data
end
DataStore:SetAsync(thekeyofplayer,data)
end

the rest you can figure out.

1 Like

I already put that function

local mascotasguardadas = miranura:GetAsync(player.UserId .. "mascotasguardadas") or {}

and execute it with a for loop