How can I make it so that it saves multiple tools with the same name?
Haven’t really figured out a solution yet, please give me some ideas. Also, please give me some code for it, because I’m new to Lua
local dss = game:GetService("DataStoreService")
local toolsDS = dss:GetDataStore("ToolsData")
local toolsFolder = game.ServerStorage.Items
game.Players.PlayerAdded:Connect(function(plr)
local toolsSaved = toolsDS:GetAsync(plr.UserId .. "-tools") or {}
for i, toolSaved in pairs(toolsSaved) do
if toolsFolder:FindFirstChild(toolSaved) then
if not plr.Backpack:FindFirstChild(toolSaved) then
toolsFolder[toolSaved]:Clone().Parent = plr.Backpack
end
if not plr.StarterGear:FindFirstChild(toolSaved) then
toolsFolder[toolSaved]:Clone().Parent = plr.StarterGear
end
end
end
plr.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
local toolInHand = humanoid:FindFirstChildOfClass("Tool")
if toolInHand then
toolInHand.Parent = plr.Backpack
end
end)
plr.CharacterRemoving:Connect(function(char)
char.Humanoid:UnequipTools()
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
local toolsOwned = {}
for _, toolInBackpack in pairs(plr.Backpack:GetChildren()) do
table.insert(toolsOwned, toolInBackpack.Name)
end
for _, toolInStarterGear in pairs(plr.StarterGear:GetChildren()) do
table.insert(toolsOwned, toolInStarterGear.Name)
end
local success, errormsg = pcall(function()
toolsDS:SetAsync(plr.UserId .. "-tools", toolsOwned)
end)
if errormsg then warn(errormsg) end
end)