local DataStore = game:GetService("DataStoreService"):GetDataStore('ToolSave') game.Players.PlayerAdded:Connect(function(plr) local savedstuff = DataStore:GetAsync(plr.userId) if savedstuff ~= nil then for i,v in pairs(savedstuff) do if game.ServerStorage.Inventory:FindFirstChild(v) ~= nil then --Inventory is a folder with Weopons inside it local weopon = game.ServerStorage.Inventory:FindFirstChild(v):Clone() weopon.Parent = plr:WaitForChild('Backpack') end end end plr.CharacterRemoving:Connect(function() plr.Character.Humanoid:UnequipTools() end) end) game.Players.PlayerRemoving:Connect(function(plr) local Table = {} for i,v in pairs(plr.Backpack:GetChildren()) do table.insert(Table,v.Name) --It uses name from what I understand end if Table ~= nil then DataStore:SetAsync(plr.userId,Table) end end)
Players can change their name so using a name as a key is a bad idea. if a player changes their name when they rejoin your game it would make a new datastore for them as if they are a new player.
A better alternative is to use a players userId. every player is assigned a unique userId that never changes so you would be better off using it.
to use it is simply player.userId
and in your case,
for i,v in pairs(plr.Backpack:GetChildren()) do table.insert(Table,v.userId) --It uses name from what I understand end