so here it saves my tools but if I have more of the same tool like for example 2 swords and equip one and leave and rejoi there is only 1 sword
local ToolFolder = game:GetService("ServerStorage"):FindFirstChild("Saved")
local DataStoreService = game:GetService("DataStoreService")
local SaveData = DataStoreService:GetDataStore("SaveData")
-- Tracks equipped tools (optional)
local EquippedTools = {}
game.Players.PlayerAdded:Connect(function(Player)
print("[JOIN]", Player.Name)
-- Load saved tools from DataStore
local ToolData
local success, err = pcall(function()
ToolData = SaveData:GetAsync(Player.UserId)
end)
if not success then
warn("[LOAD ERROR] Failed to load for", Player.Name, ":", err)
else
print("[LOAD SUCCESS]", ToolData)
end
local Backpack = Player:WaitForChild("Backpack")
local StarterGear = Player:WaitForChild("StarterGear")
if ToolData and type(ToolData) == "table" then
for _, toolName in ipairs(ToolData) do
local Tool = ToolFolder and ToolFolder:FindFirstChild(toolName)
if Tool then
-- Clone to Backpack and StarterGear (your original behavior)
local ToolClone1 = Tool:Clone()
local ToolClone2 = Tool:Clone()
ToolClone1.Parent = Backpack
ToolClone2.Parent = StarterGear
print("[LOAD] Gave", toolName, "to", Player.Name)
else
warn("[LOAD WARNING] Tool not found in ToolFolder:", toolName)
end
end
end
-- Track equipped tools (optional)
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:WaitForChild("Humanoid")
Character.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
EquippedTools[Player.UserId] = child.Name
print("[EQUIPPED]", Player.Name, "equipped", child.Name)
end
end)
Character.ChildRemoved:Connect(function(child)
if child:IsA("Tool") and EquippedTools[Player.UserId] == child.Name then
EquippedTools[Player.UserId] = nil
print("[UNEQUIPPED]", Player.Name, "unequipped", child.Name)
end
end)
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
print("[LEAVE]", Player.Name)
local ToolTable = {}
-- Save all tools from Backpack (including duplicates)
for _, tool in ipairs(Player.Backpack:GetChildren()) do
if tool:IsA("Tool") then
table.insert(ToolTable, tool.Name)
print("[SAVE] Backpack tool:", tool.Name)
end
end
-- Save all equipped tools from Character (including duplicates)
if Player.Character then
for _, tool in ipairs(Player.Character:GetChildren()) do
if tool:IsA("Tool") then
table.insert(ToolTable, tool.Name)
print("[SAVE] Equipped tool:", tool.Name)
end
end
end
print("[SAVE] Tools to save:", table.concat(ToolTable, ", "))
-- Save to DataStore
local success, err = pcall(function()
SaveData:SetAsync(Player.UserId, ToolTable)
end)
if success then
print("[SAVE SUCCESS]", Player.Name)
else
warn("[SAVE ERROR]", Player.Name, ":", err)
end
EquippedTools[Player.UserId] = nil
end)