Collection Service isnt working properly

I’m trying to make a script where there are random drops around the map, I got the drops part working the part that isn’t working is the collection service.

I made it such that it clones a dropItem and that Item has already been tagged for collection service The problem is that nothing happens
Code below:


local CollectionService = game:GetService(“CollectionService”)

local TaggedParts = CollectionService:GetTagged(“Gift”)

wait(2)

local CreateDrop = require(script:WaitForChild(“CreateDrop”))

CreateDrop.new(“Logs”,5,5,150)

for _, part in pairs(CollectionService:GetTagged(“killers”)) do

part.Touched:Connect(function(hit)

if (hit.Parent:FindFirstChild(“Humanoid”)) then

print(“Player touched”)

end

end)

end


1 Like

I would look into using CollectionService:GetInstanceAddedSignal over using a integration loop of what currently is tagged with a certain tag.

Not saying this is the definitive solution but may be able to fix issues in which you are adding tags to items during runtime.

1 Like

Thanks! the code is working properly now

1 Like

I have a very similar line of code as shown above, and it is intended to reset itself every so often after an event was triggered (to clear all the running script functions to wait for another hit). The issue is sometimes, it runs the for loop just fine, but it refuses to run the touched function within that. No errors, no disabled script, it just stops running. It runs flawless for a while, but sometimes it just stops. How can :GetInstanceAddedSignal() be used to resolve this issue? I assume it’ll work better.

TIA