This Simple Script wont work as intended

I was tryna implemeant a tool/sword saving script, but the tool wont save upon rejoining, and I was also trying to have the player still have a sword upon death, I am not using a kill script for the death as of rn, but rather “LoadCharacter”. Is that the problem?

Also whats killing me is that there is no ERRORRRRRR.

Help

local coinPurchaseSavesFolder = game:GetService("ServerStorage"):WaitForChild("CoinPurchases")
local dss = game:GetService("DataStoreService")
local coinPurchaseSave = dss:GetDataStore("CoinDataStore")


game:GetService("Players").PlayerAdded:Connect(function(plr)
	wait()
	local CurrentSaves = coinPurchaseSave:GetAsync(plr.UserId)
	
	if CurrentSaves ~= nil then
		for i,v in pairs(CurrentSaves) do	
			if coinPurchaseSavesFolder:FindFirstChild(v) and plr.Backpack:FindFirstChild(v) == nil and plr.StarterGear:FindFirstChild(v)== nil then
				coinPurchaseSavesFolder[v]:Clone().Parent = plr:FindFirstChild("BackPack")
				coinPurchaseSavesFolder[v]:Clone().Parent = plr:FindFirstChild("StarterGear")
			end
		end
	end
	local DiedSaving = {}
	plr.Character.Humanoid.Died:Connect(function()
		for i,v in pairs(plr.Character:GetChildren()) do
			if v:IsA("Tool") then
				local Cloned = v:Clone()
				table.insert(DiedSaving,Cloned)
				print("cloned and inserted")
				
			end
		end
	end)
	plr.CharacterAdded:Connect(function(char)
		if DiedSaving ~= nil then
			print("Not nil")
			for i,v in ipairs(DiedSaving) do
				v.Parent = plr.Character
			end 
		end
	end)
	plr.CharacterRemoving:Connect(function(char)
		char:WaitForChild("Humanoid"):UnequipTools()
	end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local SaveTable = {}
	for i,v in pairs(plr.Backpack:GetChildren()) do
		table.insert(SaveTable,v.Name)
	end
	if SaveTable ~= nil then
		coinPurchaseSave:SetAsync(plr.UserId,SaveTable)
	end
	
end)

Ok, you are making this quite a pain. For one, you don’t need to clone the tools inside of the character every time it dies as you already have the tool inside StarterGear, making it automatically put inside the backpack. Second, You don’t need to unequip the tools on death. Lastly, although this is unneeded considering what I am already having you do, DiedSaving never resets, meaning the tools would infinitely clone just by resetting.

local coinPurchaseSavesFolder = game:GetService("ServerStorage"):WaitForChild("CoinPurchases")
local dss = game:GetService("DataStoreService")
local coinPurchaseSave = dss:GetDataStore("CoinDataStore")


game:GetService("Players").PlayerAdded:Connect(function(plr)
	wait()
	local CurrentSaves = coinPurchaseSave:GetAsync(plr.UserId)
	
	if CurrentSaves ~= nil then
		for i,v in pairs(CurrentSaves) do	
			if coinPurchaseSavesFolder:FindFirstChild(v) and plr.Backpack:FindFirstChild(v) == nil and plr.StarterGear:FindFirstChild(v)== nil then
				coinPurchaseSavesFolder[v]:Clone().Parent = plr:FindFirstChild("BackPack")
				coinPurchaseSavesFolder[v]:Clone().Parent = plr:FindFirstChild("StarterGear")
			end
		end
	end
	
	local DiedSaving = nil
	plr.CharacterAdded:Connect(function(char)
		char:WaitForChild("Humanoid").Died:Connect(function()
			local tool = char:FindFirstChildOfClass("Tool")
			
			if tool then
				DiedSaving = tool
				tool.Parent = script
			end
		end)
		
		if DiedSaving then
			if plr.StarterGear:FindFirstChild(DiedSaving.Name) then
				plr.Backpack:WaitForChild(DiedSaving.Name).Parent = char
				DiedSaving:Destroy()
			else
				DiedSaving.Parent = char
			end
		end
	end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local SaveTable = {}
	
	for i,v in pairs(plr.Backpack:GetChildren()) do
		table.insert(SaveTable,v.Name)
	end
	
	if SaveTable ~= nil then
		coinPurchaseSave:SetAsync(plr.UserId,SaveTable)
	end
end)

Also, yes, you should definitely actually kill the Humanoid instead of just reloading the character. (I didn’t finish my last post and deleted it mb)

Yo mb for the script being a pain, just started learning; altho this fix may solve the problem, I am trying to make diedSaving a table for multiple items to be stored on; how would I go about doing that? say a player has a sword and shield equiped, this fix only saves 1 or the other item right, upon death?

Ohh, so that’s why you had it like that. I was actually quite confused why you had it save multiple items because normally the player would only have one at a time. This is what it would be for both:

local coinPurchaseSavesFolder = game:GetService("ServerStorage"):WaitForChild("CoinPurchases")
local dss = game:GetService("DataStoreService")
local coinPurchaseSave = dss:GetDataStore("CoinDataStore")


game:GetService("Players").PlayerAdded:Connect(function(plr)
	local CurrentSaves = coinPurchaseSave:GetAsync(plr.UserId)
	
	if CurrentSaves ~= nil then
		for i,v in pairs(CurrentSaves) do	
			if coinPurchaseSavesFolder:FindFirstChild(v) and plr.Backpack:FindFirstChild(v) == nil and plr.StarterGear:FindFirstChild(v)== nil then
				coinPurchaseSavesFolder[v]:Clone().Parent = plr:FindFirstChild("StarterGear")
			end
		end
	end
	
	local DiedSaving = {}
	
	plr.CharacterAdded:Connect(function(char)
		char:WaitForChild("Humanoid").Died:Connect(function()
			local tool = char:FindFirstChildOfClass("Tool")
			
			if tool then
				table.insert(DiedSaving, tool)
				tool.Parent = script
			end
		end)
		
		for i,v in pairs(DiedSaving) do
			if plr.StarterGear:FindFirstChild(v.Name) then
				plr.Backpack:WaitForChild(v.Name).Parent = char
				v:Destroy()
			else
				v.Parent = char
			end
		end
	end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local SaveTable = {}
	
	for i,v in pairs(plr.Backpack:GetChildren()) do
		table.insert(SaveTable,v.Name)
	end
	
	if SaveTable ~= nil then
		coinPurchaseSave:SetAsync(plr.UserId,SaveTable)
	end
end)

Also, that script was actually pretty good for being new, you just need to work on the quick and more efficient ways.