How do I add Creator Tags for Npc kills on my custom sword?

Hello I have been trying to make a way for when an npc is kill by a sword the player who killed the npc with the sword gains money. I need help on how to make a creator tag

These are the script that I have right now:

In the sword:

local tool = script.Parent

local canDamage = false

local function onTouch(otherPart)

local humanoid = otherPart.Parent:FindFirstChild("Humanoid")



if not humanoid then 

	return 

end



if humanoid.Parent ~= tool.Parent and canDamage then 

	humanoid:TakeDamage(10)

else

	return

end



canDamage = false

end

local function slash()

local str = Instance.new("StringValue")

str.Name = "toolanim"

str.Value = "Slash" 

str.Parent = tool

canDamage = true

end

tool.Activated:Connect(slash)

tool.Blade.Touched:Connect(onTouch)

In the npc:

local Humanoid = script.Parent.Humanoid
function Dead()
local tag = Humanoid:FindFirstChild(“creator”)
if tag ~= nil then
if tag.Value ~= nil then
local leaderstats = tag.Value:FindFirstChild(“leaderstats”)
if leaderstats ~= nil then
leaderstats.Coins.Value = leaderstats.Coins.Value +10
wait(0.1)
script:Remove()
end
end
end
end
Humanoid.Died:Connect(Dead)

1 Like
function tagHumanoid(hum)
	local existingTag = hum:FindFirstChild("creator");
	if existingTag then
		existingTag:Destroy(); --Removes any current tags on the humanoid
	end

	local tag = Instance.new("ObjectValue");
	tag.Name = "creator";
	tag.Value = game.Players:GetPlayerFromCharacter(tool.Parent); --Gets a player from their character using the tool's parent.
	tag.Parent = hum;
end

Just add this function somewhere in your script and call it when you damage the humanoid. Remember to pass the humanoid as an argument when calling it.

1 Like

dose it go in the sword script?

local tool = script.Parent

local canDamage = false

local function onTouch(otherPart)

	local humanoid = otherPart.Parent:FindFirstChild("Humanoid")



	if not humanoid then 

		return 

	end



	if humanoid.Parent ~= tool.Parent and canDamage then 
		
		tagHumanoid(humanoid);
		humanoid:TakeDamage(10)

	else

		return

	end



	canDamage = false

end

local function slash()

	local str = Instance.new("StringValue")

	str.Name = "toolanim"

	str.Value = "Slash" 

	str.Parent = tool

	canDamage = true

end

function tagHumanoid(hum)
	local existingTag = hum:FindFirstChild("creator");
	if existingTag then
		existingTag:Destroy(); --Removes any current tags on the humanoid
	end

	local tag = Instance.new("ObjectValue");
	tag.Name = "creator";
	tag.Value = game.Players:GetPlayerFromCharacter(tool.Parent); --Gets a player from their character using the tool's parent.
	tag.Parent = hum;
end

tool.Activated:Connect(slash)

tool.Blade.Touched:Connect(onTouch)```
Yes, I added it in for you. Let me know if there's any errors.
3 Likes