local ds = game:GetService("DataStoreService"):GetDataStore("Tool10") --Tools
local ds3 =  game:GetService("DataStoreService"):GetDataStore("Shield10") -- accessories
game.Players.PlayerAdded:connect(function(plr)
 local key = "id-"..plr.userId
   pcall(function()
        local tools = ds:GetAsync(key)
 	if tools then
	    for i,v in pairs(tools) do
	        local tool = game.ServerStorage.Tools:FindFirstChild(v)
	           if tool then
		 print("loading tools")
		 tool:Clone().Parent = plr:WaitForChild("Backpack")
		 tool:Clone().Parent = plr:WaitForChild("StarterGear")
	          end
	       end
	   end
		
	local Shields = ds3:GetAsync(key)
	   if Shields then
	       for i,v in pairs(Shields) do
                     local sh = game.ServerStorage.Accesss:FindFirstChild(v)
                         if sh then
		            print("loading shields")
		            local backpack = plr:WaitForChild("Backpack")
		            sh:Clone().Parent = backpack:WaitForChild("shields")
	                 end
	        end
	  end
       end)
end)




game.Players.PlayerRemoving:connect(function(plr)
   local key = "id-"..plr.userId
    pcall(function()
       local toolsToSave = {}
       local shieldsToSave = {}
            for i,v in pairs(plr.Backpack:GetChildren()) do
                if v then
                    table.insert(toolsToSave,v.Name)
               end
            end
    ds:SetAsync(key,toolsToSave)

              for i,v in pairs(plr.Backpack.shields:GetChildren()) do
                 if v then
                    print(v.Name)
                    print("saving shields")
                    table.insert(shieldsToSave,v.Name)
                 end
              end
    ds3:SetAsync(key,shieldsToSave)
   end)
wait(5)
end)

1 comment

0

Sorry, my indentions seems messed up in the post, but hopefully that is readable. LOL