Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local DataStoreService = game:GetService("DataStoreService")
- local ToolData = DataStoreService:GetDataStore("ToolSave")
- local ServerStorage = game:GetService("ServerStorage")
- local Players = game:GetService("Players")
- local function GiveSavedTools(Player)
- if not (Player) then return end
- local SavedTools
- local Success = pcall(function()
- SavedTools = ToolData:GetAsync(Player.UserId)
- end)
- if (Success and SavedTools) then
- for _,Tool in pairs(SavedTools) do
- local Tool = ServerStorage.Tools:FindFirstChild(Tool)
- if (Tool) then
- Tool:Clone().Parent = Player:WaitForChild("Backpack")
- Tool:Clone().Parent = Player:WaitForChild("StarterGear")
- end
- end
- end
- Player.CharacterRemoving:Connect(function(Character)
- local Humanoid = Character:FindFirstChildOfClass("Humanoid")
- if (Humanoid) then
- Humanoid:UnequipTools()
- end
- end)
- end
- local function SaveTools(Player)
- if not (Player) then return end
- local Backpack = Player:WaitForChild("Backpack")
- pcall(function()
- local ToolsToSave = {}
- for _,Tool in pairs(Backpack:GetChildren()) do
- if (Tool:IsA("Tool")) then
- table.insert(ToolsToSave, Tool.Name)
- end
- end
- if (#ToolsToSave < 1) then return end
- ToolData:SetAsync(Player.UserId, ToolsToSave)
- end)
- end
- Players.PlayerAdded:Connect(GiveSavedTools)
- Players.PlayerRemoving:Connect(SaveTools)
Add Comment
Please, Sign In to add comment