I need help with making a script that detects when a player is killed and adds the kill stat and the deaths stat in the leaderstats

This is the script I am working with, it is in the roblox classic sword sword script

function Blow(Hit)
	if not Hit or not Hit.Parent or not CheckIfAlive() or not ToolEquipped then
		return
	end
	local RightArm = Character:FindFirstChild("Right Arm") or Character:FindFirstChild("RightHand")
	if not RightArm then
		return
	end
	local RightGrip = RightArm:FindFirstChild("RightGrip")
	if not RightGrip or (RightGrip.Part0 ~= Handle and RightGrip.Part1 ~= Handle) then
		return
	end
	local character = Hit.Parent
	if character == Character then
		return
	end
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid or humanoid.Health == 0 then
		return
	end
	local player = Players:GetPlayerFromCharacter(character)
	if player and (player == Player or IsTeamMate(Player, player)) then
		return
	end
	UntagHumanoid(humanoid)
	TagHumanoid(humanoid, Player)
	humanoid:TakeDamage(Damage)	
-- everything past here is the part where it gives the stat
	local plr = game.Players:GetPlayerFromCharacter(humanoid.Parent)
	humanoid.Died:Connect(function()
		local killer = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
		plr:FindFirstChild("leaderstats"):WaitForChild("Deaths").Value +=1
		killer:FindFirstChild("leaderstats"):WaitForChild("Kills").Value +=1
	end)
end

The problem with this is that it keeps repeating giving the player a higher number of kills than I would like, same with the number of deaths.

You create a new script that uses Humanoid.Died function with a check that checks if the Player.Character.Humanoid:FindFirstChildOfClass(“ObjectValue”) and so on ( Your code block ). Using it into the sword script is not a good way of doing it.

You need to track which player dealt the killing blow. Its standard practice to add a ‘creator’ value to the hit player with a value of the attacking player. You will need to add checks to see if there is already a tag present to stop duplicates.

In a separate script, when a player character dies, check the creator tag for the attacking players name and award points.

There is why the roblox classic sword comes with a function called UntagHumanoid() where it removes the creator tag on blow and re-adds the new tag.

I have tried this and it does work however how would I make it so a player can be using a type of sword that can kill but wont add kills or deaths? (also sorry for late reply)