DataStore subfolder just doesn't save

Hello in my DataStore script i’m going through a player folder in ServerStorage which has the names of things i want to save then i check the same folders and what’s inside them on the player and save them. However for the inventory i’m doing it differently as i create a inventory sub folder which contains the value and attributes of my swords.

players.PlayerRemoving:Connect(function(player)
	if loaded[player]==nil then return end
	local data = {}
	for i,folder in game.ServerStorage.PlayerFolder:GetChildren() do
		local subfolder = {}
		local inventorysub = {}
		if folder.Name == "Inventory" then
			
			for i, sword in player["Inventory"]:GetChildren()do
				inventorysub[i] = {}
				inventorysub[i]["Value"] = sword.Value
				local swordAttributes = sword:GetAttributes()
				for name, value in pairs(swordAttributes) do
					inventorysub[i][name] = value
				end
			end
			data["Inventory"]= inventorysub
			print(inventorysub)
 		else
		for i, child in player[folder.Name]:GetChildren() do
			subfolder[child.Name] = child.Value
			end
			data[folder.Name] = subfolder
		end
		
		
	end
	local success, errorMessage = pcall(function()
		print("saved")
		PIS:SetAsync(player.UserId,data)
	end)
	loaded[player] = nil
end)

Anything other than inventory saves perfectly (i check it with the DataStore editor plugin)
I have no idea why the inventory doesn’t save since print(inventorysub) prints things correctly and exactly as they should be so where could the issue be?
Thanks in advance for any help.

Bump i really need help maybe i can get info on whether datastore can’t have arrays with 2 keys and is limited to 1 key

i’ve fixed the issue. my sword had Color3 attributes and when i put the Color3 value into the array it doesn’t save (although it prints normally as ["Blade"] = 1,1,1 for example.
By creating another sub folder for the colored attributes storing R G B separately i was able to fix it

for name, value in pairs(swordAttributes) do
					if name == "Blade" or name == "Grip" or name=="Handle" then
						inventorysub[i][name] = {}
						inventorysub[i][name][1] = value.r
						inventorysub[i][name][2] = value.g	
						inventorysub[i][name][3] = value.b
					else
						inventorysub[i][name] = value
					end
					
				end
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.