How would i add creator tag to my sword script

So I wanted to make a sword that give points when I kill an NPC or a Player like the sword model ROBLOX provided here’s my script. Idk how to make it work though

> local Debris = game:GetService("Debris")
> local damage = 10
> local debounce = true
> 
> function TagHumanoid(humanoid, player)
> 	local Creator_Tag = Instance.new("ObjectValue")
> 	Creator_Tag.Name = "creator"
> 	Creator_Tag.Value = player
> 	Debris:AddItem(Creator_Tag, 2)
> 	if humanoid then
> 		Creator_Tag.Parent = humanoid
> 	end
> end
> 
> function UntagHumanoid(humanoid)
> 	for i, v in pairs(humanoid:GetChildren()) do
> 		if v:IsA("ObjectValue") and v.Name == "creator" then
> 			v:Destroy()
> 		end
> 	end
> end
> 
> function attack(player)
> 	print("attack function called")
> 	local hitbox = script.Parent
> 	hitbox.Touched:Connect(function(hit)
> 		local humanoid = hit.Parent:FindFirstChild("Humanoid")
> 		if humanoid and debounce then
> 			humanoid:TakeDamage(damage)
> 			print("damaged humanoid by " .. damage)
> 			UntagHumanoid(humanoid)
> 			TagHumanoid(humanoid, player) 
> 
> 			debounce = false
> 			wait(1)
> 			debounce = true
> 		end
> 	end)
> end
> 
> 
> 
> script.Parent.Parent.Activated:Connect(function()
> 	local success, err = pcall(function()
> 	end)
> 	if success then
> 		attack()
> 	end
> ```
> end)

This is your ‘creator’ tag in your code already:

function TagHumanoid(humanoid, player)
	local Creator_Tag = Instance.new("ObjectValue")
	Creator_Tag.Name = "creator"
	Creator_Tag.Value = player
 	Debris:AddItem(Creator_Tag, 2)
	if humanoid then
		Creator_Tag.Parent = humanoid
	end
end

It is called by the attack function when it hits something which has a Humanoid.

What you need to do is add a script to your NPC with a event Died event Connected to the NPC, reads the ‘creator’ tag from your script above and awards points.

I have done those but it doesnt work somehow

Please show us the script you have in the NPC for the Died event and we can assist.

Hi thanks for the help I have fixed my problem now it was just that I wasn’t setting the value to the player

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.