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)
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.
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")
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