Is there currently a script I can use to save inventory tools in the order players arrange them in?

I have looked around but all I could come up with is this, Any help?

local dataservice = game:GetService(“DataStoreService”)
local inventorydata = dataservice:GetDataStore(“Inventory”)
local itemsfolder = game.ServerStorage.ItemsFolder --replace it to the location of your item folder

game.Players.PlayerAdded:Connect(function(player)
local inventory = inventorydata:GetAsync(player.UserId) or {}
for i, si in pairs(inventory) do
if itemsfolder:FindFirstChild(si) then
itemsfolder[si]:Clone().Parent = player.Inventory–Change this to the folder you want to copy the items back into.
end
end
end)

game.Players.PlayerRemoving:Connect(function(player)
local inventory = {}
for i, si in pairs(player.Inventory:GetChildren()) do-- Change this to the folder you want to save the children of.
table.insert(si.Name)
end
local success, errormsg = pcall(function()
inventorydata:SetAsync(player.UserId, inventory)
end)
if errormsg then warn(errormsg)
end)

2 Likes

When adding to the table try to do it numbered liked

local Inventory = {
[1] = "Item",
[2] = "Item",
[3] = "Item",
[4] = "Item",
[5] = "Item",
[6] = "Item",
[7] = "Item",
[8] = "Item",
[9] = "Item",
[0] = "Item"}

EDIT : Or do ipairs instead of just pairs