Advertisement
Sungmingamerpro13

SaveToolsScript

Jan 26th, 2023
1,015
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 1.21 KB | None | 0 0
  1. local ToolsFolder = game:GetService("ServerStorage"):FindFirstChild("SavedTools")
  2. local DataStoreService = game:GetService("DataStoreService")
  3. local SaveData = DataStoreService:GetDataStore("SaveData")
  4.  
  5. game.Players.PlayerAdded:Connect(function(player)
  6.    
  7.     local ToolData = SaveData:GetAsync(player.UserId)
  8.    
  9.     local Backpack = player:WaitForChild("Backpack")
  10.     local StarterGear = player:WaitForChild("StarterGear")
  11.    
  12.     if ToolData ~= nil then
  13.         for i, v in pairs(ToolData) do
  14.             if ToolsFolder:FindFirstChild(v) and Backpack:FindFirstChild(v) == nil and StarterGear:FindFirstChild(v) == nil then
  15.                 ToolsFolder[v]:Clone().Parent = Backpack
  16.                 ToolsFolder[v]:Clone().Parent = StarterGear
  17.             end
  18.         end
  19.     end
  20.    
  21.     player.CharacterRemoving:Connect(function(character)
  22.         character:WaitForChild("Model"):UnequipTools()
  23.     end)
  24. end)
  25.  
  26. game.Players.PlayerRemoving:Connect(function(player)
  27.     local ToolsTable = {}
  28.    
  29.     for i, v in pairs(player.Backpack:GetChildren()) do
  30.         table.insert(ToolsTable, v.Name)
  31.     end
  32.    
  33.     if ToolsTable ~= nil then
  34.         SaveData:SetAsync(player.UserId, ToolsTable)
  35.     end
  36. end)
  37.  
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement