#How do I make Collection service apply to clones tools?

1 messages · Page 1 of 1 (latest)

worn jolt
#

local clone = CollectionService:GetTagged("ClonePrompt")
local tool = CollectionService:GetTagged("Tools")

for i,prompt in pairs(clone) do
    local part = prompt.Parent
    local tool = game.ReplicatedStorage:WaitForChild("Pod")

    prompt.Triggered:Connect(function(h)
        local newTool = tool:Clone()
        newTool:AddTag("Tools")

        newTool.Parent = h.Backpack
        part:Destroy()
    end)
end

for i,tool in pairs(tool) do
    tool.Activated:Connect(function()
        tool:Destroy()
    end)
end```

It doesnt seem to work
raven spruceBOT
#

studio** You are now Level 1! **studio

faint bramble
#

you're reusing the same old list, not getting the new updated one

worn jolt
faint bramble
#

like:

local tool = CollectionService:GetTagged("Tools")
for i,tool in pairs(tool) do
    tool.Activated:Connect(function()
        tool:Destroy()
    end)
end
#

you also have several variables with the same name which i dont recommend

#

can get confusing

worn jolt
#

wait I forgot to change a tag

worn jolt
# worn jolt Like this?
local CollectionService = game:GetService("CollectionService")

local clones = CollectionService:GetTagged("Clone")

for i,prompt in pairs(clones) do
    local part = prompt.Parent
    local toolToClone = game.ReplicatedStorage:WaitForChild("Pod")

    prompt.Triggered:Connect(function(h)
        local newTool = toolToClone:Clone()
        newTool:AddTag("Tool")
        
        newTool.Parent = h.Backpack
        part:Destroy()
    end)
end


local tools = CollectionService:GetTagged("Tool")
for i,tool in pairs(tools) do
    tool.Activated:Connect(function()
        tool:Destroy()
    end)
end