Mutliple People One Tag

Hello, I am trying to make a tagging system that can fit multiple people inside it so that every gets a reward i have tried it myself and i have not been able to find a solution does anyone know one?

My script so far

   function TagHumanoid(eHum, player)
	if not eHum:FindFirstChild("creator") then
		local Creator_Tag = Instance.new("ObjectValue")
		Creator_Tag.Name = "creator"
		Creator_Tag.Value = player
		game.Debris:AddItem(Creator_Tag, 5)
		Creator_Tag.Parent = eHum
	elseif eHum:FindFirstChild("creator") then
		local Creator_Tag = Instance.new("ObjectValue")
		Creator_Tag.Name = "creator"
		Creator_Tag.Value = Creator_Tag.Value..player 
		game.Debris:AddItem(Creator_Tag, 5)
		Creator_Tag.Parent = eHum
	end
end

If it’s instance based then you don’t need to fit multiple people in one tag, you just need to iterate over the Humanoid and check for ObjectValue instances that are named “creator” and act accordingly on them. Remove your duplication guards as well.

-- Tagging a humanoid
local function tagHumanoid(humanoid, player)
    local creator = Instance.new("ObjectValue")
    creator.Name = "creator"
    creator.Value = player
    task.delay(5, creator.Destroy, creator)
    creator.Parent = humanoid
end

-- Acting on all players who tagged a humanoid
for _, tag in ipairs(humanoid:GetChildren()) do
    if not (tag:IsA("ObjectValue") and tag.Name == "creator") then continue end
    print(tag.Value, "tagged", humanoid)
end

ObjectValues can only contain a single reference to an instance but in your case you were trying to treat it like a StringValue as well as the player instances as strings. Can’t concatenate non-strings that way.

It would probably be more apt for you to use a dictionary though and set keys in it then iterate over said dictionary for people who tagged the humanoid.

1 Like