How to detect if a clone of something is a certain object

So I’m trying to make it so that if a specific object is cloned, the cloned object has a tag added onto it, but I don’t know how to detect if something specific gets cloned.

local Part = script.Parent
local CollectionService = game:GetService("CollectionService")
local DB = false

local function give(Player)
	local tool = script.Parent.Selection:FindFirstChild("Loot"..math.random(1,4))
	local lightammo = script.Parent.Selection:FindFirstChild("Loot1")
	local rifleammo = script.Parent.Selection:FindFirstChild("Loot2" and "Loot3" and "Loot4")
	local clone = tool.Value:Clone()
	
	if lightammo then
		print("yayy")
		CollectionService:AddTag(clone, "LightAmmo")
	end
	
	if rifleammo then
		print("hghgf")
		CollectionService:AddTag(clone, "LightAmmo")
	end

	if not DB and tool then
		DB = true
		Part.Transparency = 1
		Part.Equip:Play()
		Part.CanCollide = false
		Part.ClickDetector.MaxActivationDistance = 0
		clone.Parent = game.Workspace
		clone.CFrame = Part.CFrame * CFrame.Angles(math.random(1,360), 0, 0) + Vector3.new(math.random(-0.5,0.5),nil,math.random(-0.5,0.5))

		wait(2)

		DB = false
		Part.Transparency = 0
		Part.CanCollide = true
		Part.ClickDetector.MaxActivationDistance = 5
	end
end

Part.ClickDetector.MouseClick:Connect(give)
1 Like

what you can do is just check if the cloned object has a tag inside it

1 Like

if the cloned object wasn’t cloned before, you can store a value for it in a table inside the function that clones the object. there are many ways to check this.

I’m pretty sure I can use a for i,v loop to search through the tags, but how would I make it only loop through for the cloned parts that have the tag?

hey, so you can loop through an object’s tags using CollectionService:GetTags(instance: Instance), which just returns on array. you could also use CollectionService:GetTagged(tag: String) which returns an array of objects with the specified tag. u can then check if the object is contained in that array. lastly, you can alternatively use Instance:SetAttribute(attribute: String, value: Varient) and Instance:GetAttributes() for an easier method opposed to tags

1 Like

But how would I do those things only to an instance that is cloned?

So when you clone on object, you have that clone stored to a variable. What you can do is add an attribute or tag that clone so that other scripts can read it

the rifleammo variable will always search for “Loot4” because
("Loop2" and "Loop3" and "Loop4") == "Loop4"

I would do it like this:
local rifleammo = script.Parent.Selection:FindFirstChild("Loot2") or script.Parent.Selection:FindFirstChild("Loot3") or script.Parent.Selection:FindFirstChild("Loot4")

But the clone is a randomized object

Can you elaborate on why you need to confirm something is a clone?

I have this other script that uses collection service for ammo, and I want ammo boxes to despawn every couple of minutes and I have this loot system that clones the ammo boxes, and the ammo box models have this tag on them, but they get deleted after a couple of minutes due to the ammo box script, so the looting part can’t clone the ammo