Saving a player's Inventory?

Hey!

I am wondering if there is a tutorial you guys know where I can look for what I am looking for. I am wondering if there is a way to save whats inside a folder, with ProfileService? For an example a players Inventory. The folder is parented into the player, and the folder holds StringValues with the name of the weapon. I want to save those values, so when the player rejoins, they get they’re weapons back that was saved.

Here is the normal script that I use with DataStoreService.

local DataStore = game:GetService("DataStoreService"):GetDataStore("GunSaving")

local Players = game:GetService("Players")

local function addFolderGuns(player)
	local folder = Instance.new("Folder")
	folder.Name = "myInventory"
	folder.Parent = player

	local data

	local success, errorMsg = pcall(function()
		data = DataStore:GetAsync(player.UserId)
	end)

	if data ~= nil then
		if data.Inventory then
			for index,inventory  in pairs(data.Inventory) do
				local bool = Instance.new("StringValue",folder); bool.Name = inventory
			end
		end
	else
		-- New player
		print("A new player has joined")
	end
end

game.Players.PlayerAdded:Connect(addFolderGuns)

for _, player in pairs(Players:GetPlayers()) do
	spawn(function()
		addFolderGuns()
	end)
end

game.Players.PlayerRemoving:Connect(function(plr)
	local data = {}

	data.Inventory = {}

	for i,v in pairs(plr.myInventory:GetChildren()) do
		table.insert(data.Inventory,v.Name)
	end

	local success, errorMsg = pcall(function()
		DataStore:SetAsync(plr.UserId,data)
	end)

	-- if its succeed then the data is saved else we got an error

	if success then 
		print("Succesfully saved") 
	else 
		print(errorMsg) 
	end

end)

local function gameBindSave(plr)
	local data = {}

	data.Inventory = {}

	for i,v in pairs(plr.myInventory:GetChildren()) do
		table.insert(data.Inventory,v.Name)
	end

	local success, errorMsg = pcall(function()
		DataStore:SetAsync(plr.UserId,data)
	end)

	-- if its succeed then the data is saved else we got an error

	if success then 
		print("Succesfully saved") 
	else 
		print(errorMsg) 
	end
end

game:BindToClose(function()
	wait(1.5)
	for _, v in pairs(Players:GetPlayers()) do
		gameBindSave(v)
	end
end)

I am wanting to use ProfileService because it is more modern, and it saves more better than normal DataStore.

Let me know if you have a link, or a normal suggestion so I can get a solution for my problem.

Thank you very much Dev’s!

Sincerely,

papahetfan