RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"a datastore for tools in players backpack when players leave and load in"
-- server script local DataStoreService = game:GetService("DataStoreService") local toolDataStore = DataStoreService:GetDataStore("ToolData") game.Players.PlayerAdded:Connect(function(player) local playerTools = Instance.new("Folder") playerTools.Name = "PlayerTools" playerTools.Parent = player local data local success, errorMessage = pcall(function() data = toolDataStore:GetAsync(player.UserId) end) if success and data then for _, toolName in ipairs(data) do local tool = game.ServerStorage.Tools:FindFirstChild(toolName) if tool then tool:Clone().Parent = playerTools end end end end) game.Players.PlayerRemoving:Connect(function(player) local playerTools = player:FindFirstChild("PlayerTools") if playerTools then local data = {} for _, tool in ipairs(playerTools:GetChildren()) do table.insert(data, tool.Name) end local success, errorMessage = pcall(function() toolDataStore:SetAsync(player.UserId, data) end) if not success then warn("Failed to save data for player " .. player.Name .. ": " .. errorMessage) end end end)