I am trying to make knife tag players, but it wont work

I copied the tagging script from the classic sword and added it to my local script in my knife. This is whati have. This is a shortended version, everything works apart from tagging.

local Player = game.Players.LocalPlayer
Debris = game:GetService("Debris")

function TagHumanoid(humanoid, player)
	local Creator_Tag = Instance.new("ObjectValue")
	Creator_Tag.Name = "creator"
	Creator_Tag.Value = player
	Debris:AddItem(Creator_Tag, 2)
	Creator_Tag.Parent = humanoid
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


Mouse.Button1Down:Connect(function()
	if Swinging == false and Equipped == true then
		local LoadedAnim = ChooseAttack()
		if LoadedAnim then
			LoadedAnim:Play()
			Swinging = true
			Active = true
			if SwingAudio then
				SoundEvent:FireServer(SwingAudio)
			end
			
			Handle.Touched:Connect(function(part)
				if Swinging == true and Hit == false and Active == true then
					if part.Parent:FindFirstChild("Humanoid") then
						local TargetHumanoid = part.Parent:FindFirstChild("Humanoid")
						Hit = true
						
						if TargetHumanoid.Health > 0 then
							Humanoid.WalkSpeed = 5
							UntagHumanoid(Humanoid) -- untagging here
	                        TagHumanoid(Humanoid, TargetHumanoid) -- Tagging here
							Event:FireServer(TargetHumanoid, Damage)
							if HitAudio then
								SoundEvent:FireServer(HitAudio)
							end
							wait(LoadedAnim.Length)
							WaitAnim:Play()
						end
						
					elseif part.Parent.Parent:FindFirstChild("Humanoid") then
						local TargetHumanoid = part.Parent.Parent:FindFirstChild("Humanoid")
						local TargetCharacter = TargetHumanoid.Parent
						local TargetPlayer = game.Players:GetPlayerFromCharacter(TargetCharacter)
						Hit = true
						
						if TargetHumanoid.Health > 0 then
							Humanoid.WalkSpeed = 5
							UntagHumanoid(Humanoid) -- Untagging here
	                        TagHumanoid(Humanoid, TargetPlayer) -- Tagging here
							Event:FireServer(TargetHumanoid, Damage)
							
							if HitAudio then
								SoundEvent:FireServer(HitAudio)
							end
							wait(LoadedAnim.Length)
							WaitAnim:Play()
						end
					end
				end
			end)

			wait(LoadedAnim.Length) --recovery
			Active = false
			wait(2)
			Humanoid.WalkSpeed = 11
			Swinging = false
			Hit = false
		end
	end
end)

there is a few issues i can see here,

  1. Its not as simple as copy and paste, I personally would learn to code If i was you.
  2. Have you linked it all right?
  3. Have you got the Animation in there?

This is a shortened version everything works.

What is the error then?

We can’t help you if we dont have an error.

(Output / Console)

There is no error, its just not tagging.

What is the Tagging doing?

From what I can see its just naming someone.

This is the exact same tagging functions in the classic sword, i have a points script that gives player points if they kill someone else, the classic sword works and gives me points but not my knife.

Are you creating the tag on the client? If it’s in a local script the server might not be able to see the creator tag.

1 Like

I think that might be the problem but it may be something wrong with my script.

Let me elaborate what retroblocx said, are you using a LocalScript or a normal Script?
Although it’s an empty question to ask since you have Players.LocalPlayer in your code which only can be used in LocalScript.

You need to re-create the code with a normal Script that will be in the tool and do the tagging process.

Edit: The reason for a normal script is, the tag creation and change process is server’s job. LocalScript can’t handle it.

1 Like

I would like to add that you seem to be putting the wrong arguments for TagHumanoid(). The first parameter should be the humanoid that you are tagging, in this case TargetHumanoid. The second parameter is the player instance. Also, I don’t see Humanoid being declared anywhere?

Ok, I Guess As I Can See Thats A LocalScript Because the :FireServer
I Think The Error Can Be At The TagHumanoid Function
Because Its Destroying The Tag Before Even Parenting It

function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new(“ObjectValue”,humanoid)
Creator_Tag.Name = “creator”
Creator_Tag.Value = player --Debris Was Here
Debris:AddItem(Creator_Tag, 2) --Parenting Was Here
end

That doesn’t make a difference as the tag is set to be destroyed after 2 seconds and Debris:AddItem() doesn’t pause the script, so the tag is parented as expected (clientside at least, must be done on server). It just isn’t parented to the right humanoid.