I have tested this script and it works, also you could use StarterGear instead but it’s up to you and don’t use DataStore for this, use it only when you have to save something when the player leaves the game, not when they die.
local PlayersTools = {}
function OnCharacterAdded(Character)
task.wait(1)
local Humanoid = Character:WaitForChild("Humanoid")
local Player = game.Players:GetPlayerFromCharacter(Character)
Humanoid.Died:Connect(function()
local NewFolder = Instance.new("Folder",game.ServerStorage)
NewFolder.Name = Player.Name.."'s Tools"
for _, Tool in pairs(Character:GetChildren()) do
if Tool:IsA("Tool") then
Tool.Parent = NewFolder
end
end
for _, Tool in pairs(Player.Backpack:GetChildren()) do
if Tool:IsA("Tool") then
Tool.Parent = NewFolder
end
end
repeat wait() until Player.Character ~= Character
for _, Tool in pairs(NewFolder:GetChildren()) do
Tool.Parent = Player.Backpack
end
NewFolder:Destroy()
end)
end
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(OnCharacterAdded)
if Player.Character then OnCharacterAdded(Player.Character) end
end)