Advertisement
Sungmingamerpro13

SaveToolsScript + TeleportService v2

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