How do I save children from a folder to a data table?

how do I save children from a folder to a data table?

Data I want to save: player.Pets:GetChildren()

Where I want to save the data to: DataObject[2]

Save data code:

game.Players.PlayerRemoving:Connect(function(player)
    local DataObject = {player.leaderstats.Cash.Value, {}}
    --Data I want to save: player.Pets:GetChildren()
    --Where I want to save the data to: DataObject[2]
    local success,fail = pcall(function()
        print("Player data syncing")
        Datastore:SetAsync(player.UserId.. "Data",DataObject)
    end)
    
    if success then
        print("Data saved successfully: ", DataObject)
    else
        warn("Error saving data" ..fail)
    end
end)

Ignore my previous statement, please look into these solutions: If they help please mark this as the solution.

I found some solutions of requests similar to what you asked for:

3 Likes