How would I create a tag to tell a script who killed another person in game?


Explanation

Alright, this is a bit of a weird one but I want to be able to record when someone kills another person; what I mean by this is, if say Player1 Killed Player2, Player1 would get a point on a leaderboard stat for Knockouts and vice versa.

Issue

The only way I know how to is quite problematic. My only knowledge of how to do something like this properly is to add a object value into the Humanoid and have the value set to the player who kills them, however this then cause for a spam of these Values to come into play.

Fixes I tried

I tried adding a check value but then it didn’t always record the value as it was blanking itself, plus if I keep it in the humanoid for too long and that person dies, it will give a free fall to the said person who last attacked him. Which I also want to prevent.


Tag Script

This is the script functions I’m using, it can be used with a Sword Tool in a sense as I’m basing it off of that.

	["mark player"] = function(Hum)
		local Hum = Hum:WaitForChild("Humanoid")
		local Holder = game.Players:GetPlayerFromCharacter(Tool.Parent)
		local creator_tag = Instance.new("ObjectValue")
		creator_tag.Value = Holder
		creator_tag.Name = "creator"
		creator_tag.Parent = Hum
	end
	;
	["unmark player"] = function(Hum)
		Hum = Hum:WaitForChild("Humanoid")
		if Hum ~= nil then
			local CreatorTag = Hum:FindFirstChild("creator")
			if CreatorTag ~= nil then
				CreatorTag.Value = nil
			end
		end
	end
Tool.Handle.Touched:Connect(function(hit)
	if hit.Parent.Name ~= "Workspace" and hit.Parent.Name ~= Tool.Parent.Name and hit.Parent ~= nil then
		FindFunction("Touch",hit.Parent)
	end
end)

If you have any ideas, please let me know.

1 Like

Why are you defining the creator_tag variable twice? You don’t need to check if the Humanoid will already have a creator Value in it, you just need to create it once

That was a typing error, you can ignore the local creator_tag = Hum:FindFirstChild("creator").

Looking at your script for a good while, couldn’t you just implement a check in your Touched Event to check if there’s a creator_tag?

	["mark player"] = function(Hum)
		local Hum = Hum:WaitForChild("Humanoid")
		local Holder = game.Players:GetPlayerFromCharacter(Tool.Parent)
		local creator_tag = Instance.new("ObjectValue")
		creator_tag.Value = Holder
		creator_tag.Name = "creator"
		creator_tag.Parent = Hum
	end
	;
	["unmark player"] = function(Hum)
		Hum = Hum:WaitForChild("Humanoid")
		if Hum ~= nil then
			local CreatorTag = Hum:FindFirstChild("creator")
			if CreatorTag ~= nil then
				CreatorTag.Value = nil
			end
		end
	end
Tool.Handle.Touched:Connect(function(hit)
	if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
        if hit.Parent.Humanoid:FindFirstChild("creator") == nil then
		    FindFunction("Touch",hit.Parent)
        end
	end
end)
2 Likes

Only issue is, if their is a creator value; it can be stolen consistently but I mean, I guess that could be a possibility. I just didn’t know what would be more efficient and if there would be a better way.