My game has swords that decrease in durability every time you hit a humanoid. This durability value is stored inside the tool itself, using an IntValue (don’t mind the other properties folder, I use it for stable values like damage or armor piercing, while durability is the only property that changes over gameplay).
I am currently saving all tools from a player’s inventory (including swords) in this manner:
players.PlayerRemoving:Connect(function(player)
local savedTools = {}
local currentTools = player.Backpack:GetChildren()
for i, v in pairs(currentTools) do
table.insert(savedTools, v.Name)
end
inventoryData:UpdateAsync(key, function(prev)
print("Saved tools!")
return savedTools
end)
end)
And this is how I load all the items:
players.PlayerAdded:Connect(function(player)
local key = player.Name .. "'s inventory"
local inventory = inventoryData:GetAsync(key)
local backpack = player.Backpack
for i, v in pairs(inventory or {}) do
local toolName = v
for i2, v2 in pairs(tools) do
if toolName == v2.Name then
local clonedTool = v2:Clone()
clonedTool.Parent = backpack
end
end
end
end)
I’m not sure how to begin solving this problem at all. I want to save each durability value for each sword in the backpack accordingly, upon leaving, then load the same durability for each sword, upon rejoining. How would I approach this?