Advertisement
Sungmingamerpro13

SaveToolsScript + TeleportService

Jan 26th, 2023
1,546
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 1.27 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local ToolsFolder = game:GetService("ServerStorage"):FindFirstChild("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]:Clone().Parent = Backpack
  17.                 ToolsFolder[v]:Clone().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.  
Tags: Roblox
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement