RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"make me a script that saves the tools when they leave the game"
-- server script local DataStoreService = game:GetService("DataStoreService") local toolDataStore = DataStoreService:GetDataStore("ToolData") game.Players.PlayerRemoving:Connect(function(player) local toolsToSave = {} for _, tool in ipairs(player.Backpack:GetChildren()) do if tool:IsA("Tool") then table.insert(toolsToSave, tool.Name) end end local success, errorMessage = pcall(function() toolDataStore:SetAsync(player.UserId, toolsToSave) end) if not success then warn("Failed to save tools for player " .. player.Name .. ": " .. errorMessage) end end) game.Players.PlayerAdded:Connect(function(player) local success, savedTools = pcall(function() return toolDataStore:GetAsync(player.UserId) end) if success and savedTools then player.CharacterAdded:Connect(function(character) for _, toolName in ipairs(savedTools) do local tool = game.ServerStorage:FindFirstChild(toolName) if tool then tool:Clone().Parent = player.Backpack end end end) else warn("Failed to load tools for player " .. player.Name) end end)