Advertisement
BlasterBladethefox

Untitled

Apr 22nd, 2021
1,166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.76 KB | None | 0 0
  1. local ds = game:GetService("DataStoreService"):GetDataStore("ToolSave")
  2. game.Players.PlayerAdded:connect(function(plr)
  3.  local key = "id-"..plr.userId
  4.  pcall(function()
  5.   local tools = ds:GetAsync(key)
  6.   if tools then
  7.    for i,v in pairs(tools) do
  8.     local tool = game.ServerStorage.Tools:FindFirstChild(v)
  9.     if tool then
  10.      tool:Clone().Parent = plr:WaitForChild("Backpack")
  11.      tool:Clone().Parent = plr:WaitForChild("StarterGear")
  12.     end
  13.    end
  14.   end
  15.  end)
  16. end)
  17. game.Players.PlayerRemoving:connect(function(plr)
  18.  local key = "id-"..plr.userId
  19.  pcall(function()
  20.   local toolsToSave = {}
  21.   for i,v in pairs(plr.Backpack:GetChildren()) do
  22.    if v then
  23.     table.insert(toolsToSave,v.Name)
  24.    end
  25.   end
  26.   ds:SetAsync(key,toolsToSave)
  27.  end)
  28. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement