Advertisement
HowToRoblox

ToolSaver

May 18th, 2020
21,199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.96 KB | None | 0 0
  1. local dss = game:GetService("DataStoreService")
  2. local toolsDS = dss:GetDataStore("ToolsData")
  3.  
  4. local toolsFolder = game.ServerStorage.ToolsFolder
  5.  
  6. game.Players.PlayerAdded:Connect(function(plr)
  7.    
  8.     local toolsSaved = toolsDS:GetAsync(plr.UserId .. "-tools") or {}
  9.    
  10.     for i, toolSaved in pairs(toolsSaved) do
  11.            
  12.         if toolsFolder:FindFirstChild(toolSaved) then
  13.            
  14.             toolsFolder[toolSaved]:Clone().Parent = plr.Backpack
  15.             toolsFolder[toolSaved]:Clone().Parent = plr.StarterGear
  16.         end
  17.     end
  18.    
  19.     plr.CharacterRemoving:Connect(function(char)
  20.        
  21.         char.Humanoid:UnequipTools()
  22.     end)
  23. end)
  24.  
  25.  
  26. game.Players.PlayerRemoving:Connect(function(plr)
  27.    
  28.     local toolsOwned = {}
  29.    
  30.     for i, toolInBackpack in pairs(plr.Backpack:GetChildren()) do
  31.        
  32.         table.insert(toolsOwned, toolInBackpack.Name)
  33.     end
  34.    
  35.     local success, errormsg = pcall(function()
  36.        
  37.         toolsDS:SetAsync(plr.UserId .. "-tools", toolsOwned)
  38.     end)
  39.     if errormsg then warn(errormsg) end
  40. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement