How can I store values inside of a folder inside of a main folder?

Ok so the idea here is to save these values, as shown in the following picture:
image
(What I want to save is the value of Optic, Barrel, etc. Each subfolder has these exact 4 string value copies, and the subfolder is the name of the tool.)

So far, I have began writing this code after some research on this, but could not find a solution.

local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("Attachments")



game.Players.PlayerAdded:Connect(function(plr)
	
	local guns = Instance.new("Folder",plr)
	guns.Name = "WeaponAttachments"
	wait(4)
	for i,v in pairs(plr.Backpack:GetChildren()) do
		--	print(v.Nlame)
		local weapon = Instance.new("Folder",guns)
		weapon.Name = v.Name
		local at1 = Instance.new("StringValue", weapon)
		at1.Name = "Optic"
		local at2 = Instance.new("StringValue", weapon)
		at2.Name = "Barrel"
		local at3 = Instance.new("StringValue", weapon)
		at3.Name = "UnderBarrel"
		local at4 = Instance.new("StringValue", weapon)
		at4.Name = "Other"
	end
	
	wait(1)
	
	--The stuff prior to this is how I got the folders shown in the script.
	
	local atts = {} 
	atts.insert(plr:WaitForChild("WeaponAttachments"))
	
	
	local data = {}
	for i, v in pairs(guns:GetChildren())  do
		data[v.Name] = {}
		for i,g in pairs(v:GetChildren()) do
			data.insert(v.Name, g)
		end
	end
	print(atts)

end)

When I try to see the table with print, however, it states this:


Any help? I have been working on this for an hour and can’t fix it.

I assume you tried to call :print() on the table based on the error. table does not have a print method. You can do print(myTable), but this just prints the table’s address. To get the kind of “pretty” print out you probably want you have to write a method yourself.

How would I do that? I am very new at scripting and I don’t even know if the code I did would even do what I want it to do.

Knowing that people would want to convert tables to and from strings for use with DataStore, there is a function that does this for you: HttpService | Roblox Creator Documentation

local myTable = {
	subTable = {
		loose = "moose",
		money = 99,
	},
	value1 = 20,
	value2 = 540,
}

local httpService = game:GetService("HttpService")

print(httpService:JSONEncode(myTable))

This prints {"value2":540,"subTable":{"money":99,"loose":"moose"},"value1":20}

The only thing you’d have to add is the conversion from table to folders and back, which is a bit easier.