RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"Create a script that saves a players item using a folder called Tools in ServerStorage"
-- server script local DataStoreService = game:GetService("DataStoreService") local myDataStore = DataStoreService:GetDataStore("PlayerTools") local ServerStorage = game:GetService("ServerStorage") local ToolsFolder = ServerStorage:WaitForChild("Tools") game.Players.PlayerAdded:Connect(function(player) local success, data = pcall(function() return myDataStore:GetAsync(player.UserId) end) if success and data then for _, toolName in ipairs(data) do local tool = ToolsFolder:FindFirstChild(toolName) if tool then tool:Clone().Parent = player.Backpack end end end end) game.Players.PlayerRemoving:Connect(function(player) local toolsToSave = {} for _, tool in ipairs(player.Backpack:GetChildren()) do if ToolsFolder:FindFirstChild(tool.Name) then table.insert(toolsToSave, tool.Name) end end local success, err = pcall(function() myDataStore:SetAsync(player.UserId, toolsToSave) end) if not success then warn("Failed to save data for " .. player.Name .. ": " .. err) end end)