How To Not Save Tools On Death

So basically, I have a script that saves the players tools when they leave or join. However, I want it to not save the tools when they die, is there a way to do this? Here is the script I am using:

local ToolFolder = game:GetService("ReplicatedStorage"):FindFirstChild("BuyableItems")
local DataStoreService = game:GetService("DataStoreService")
local SaveData = DataStoreService:GetDataStore("SaveData")

game.Players.PlayerAdded:Connect(function(Player)
	local ToolData = SaveData:GetAsync(Player.UserId)

	local Backpack = Player:WaitForChild("Backpack")
	local StarterGear = Player:WaitForChild("StarterGear")

	if ToolData ~= nil then
		for i,v in pairs(ToolData) do
			if ToolFolder:FindFirstChild(v) and Backpack:FindFirstChild(v) == nil and StarterGear:FindFirstChild(v) == nil then
				ToolFolder[v]:Clone{}.Parent = Backpack
				ToolFolder[v]:Clone{}.Parent = StarterGear
			end
		end
	end

	Player.CharacterRemoving:Connect(function(Character)
		Character:WaitForChild("Humanoid"):UnequipTools()
	end)
end)

game.Players.PlayerRemoving:Connect(function(Player)
	local ToolTable = {}

	for i, v in pairs(Player.Backpack:GetChildren()) do
		table.insert(ToolTable, v.Name)
		print(ToolTable)
	end
	if ToolTable ~= nil then
		SaveData:SetAsync(Player.UserId, ToolTable)
	end
end)

Any help is appreciated :slight_smile:

idk if this is the solution but, dont put the tool in startergear

That works, but now my avatar is a noob (?) Basically it just reset my avatar

what u mean noob? did the avatar not loaded?, or u have a function somewhere that requires the tool to exist before giving them the outfit or something?

oh you mean u dont want to keep firing the datastore saving everytime they respawn?, the script rn is suppose to work well (i think) since it doesnt have an event when they die that leads to saving datastore

``
local Items = {}
game.Players.PlayerAdded:Connect(function(Player)

repeat wait() until Player.Character

Player.Character.Humanoid.Died:Connect(function()

for i,v in pairs(Player.Backpack:GetChildren()) do

table.insert(Items,v.Name)

end

end)

Player.CharacterAdded:Connect(function()

for i,v in pairs(Items) do

game.tools location[Items[i]]:Clone().Parent = Player.Backpack

table.remove(Items,v)

end
end)

end)
``