Why isn't this saving?

I’m am trying to save a lot of folders that have different weapons and their data but every time I saving the data it gives the error
“Cannot store Dictionary in data store. Data stores can only accept valid UTF-8 characters”
I don’t understand why. I did try making the folders into tables that hold the values and it still doesn’t work.

Here is the code

local function folderToDictionary(folder)
	local dictionary = {}

	for _, object in ipairs(folder:GetChildren()) do
		if object:IsA("Folder") then
			dictionary[object.Name] = folderToDictionary(object)
		elseif object:IsA("ValueBase") or object.ClassName:match("Value") then
			dictionary[object.Name] = object.Value
		end
	end

	return dictionary
end

game.Players.PlayerRemoving:Connect(function(plr)
	local plrData = folderToDictionary(plr.Weapons)
	print(plrData)
	local Success,err = pcall(function()
		DataStore:SetAsync(plr.UserId,data)
	end)
end)

Any help would be very useful and thank you

What line is this erroring on?

DataStore:SetAsync(plr.UserId,data)
this one

You can’t save object values in datastore, you need to serialize them first. So you should try saving it by their names or properties

So find the children and save them one at a time?

ohhh i forgot that only strings and numbers can be saved

Save their names and their properties if it’s needed