I’m making a system to save the id’s of the items I want to save, because the previous one saved the names and if I changed the name of an item it would vanish from the player’s inventory
local sss = game:GetService("ServerScriptService")
local ItemData = require(sss.Modules.ItemData)
---Some Code
game.Players.PlayerRemoving:Connect(function(plr)
local key = "id-" .. plr.userId
local itemsToSave = {}
local success, errormessage = pcall(function()
for i, v in ipairs(plr.Inventory:GetChildren()) do
if v then
print(ItemData[v.Name].Id..","..v.Name)
table.insert(itemsToSave, ItemData[v.Name].Id)
end
end
DS:SetAsync(key, itemsToSave)
end)
if success then
print("SuccessFully Saved")
for i,v in ipairs(itemsToSave) do
print(v)
end
elseif errormessage then
print("Something Went Wrong")
warn(errormessage)
end
end)
Inside the ItemData:
local ItemData = {
--- Same Thing
["Miner's Helmet"] = {
SomeValues = 10;-- Aren't Important
SomeValues = 5;
SomeValues = 20;
SomeValues = 0;
Id = 27;
};
["Miner's Shirt"] = {
SomeValues = 10;
SomeValues = 0;
SomeValues = 20;
SomeValues = 0;
Id = 28;-- This is what I'm trying to focus on
};
}