Collection Service is bugged or am in the wrong?

local collectionService = game:GetService(“CollectionService”)

local cursedElement = collectionService:GetTagged(“CursedElement”)

local players = game:GetService(“Players”)
local fallPart = workspace.Course.FallPart:WaitForChild(“FallPart”)

for _, cursedPart in pairs(cursedElement) do
cursedPart.Touched:Connect(function(otherPart)
print(“Hello”)
end)
end

I don’t see anything wrong with the script but the print statement just wont fire when I touched the part

Try adding prints to see if anything is nil.

when i looked at your code the quotes seem to be messed up i redid them with singles…

also when the script runs and this get the tagged items the tagged parts may not be in workspace yet or loaded in…
you can get any that add with the GetInstanceAddedSignal

local collectionService = game:GetService('CollectionService')

local cursedElement = collectionService:GetTagged('CursedElement')

local players = game:GetService('Players')
local fallPart = workspace.Course.FallPart:WaitForChild('FallPart')

function SetupTouched(cursedPart)
	cursedPart.Touched:Connect(function(otherPart)
		print('Hello')
	end)
end

for _, cursedPart in pairs(cursedElement) do
	SetupTouched(cursedPart)
end

collectionService:GetInstanceAddedSignal('CursedElement'):Connect(function(cursedPart)
	SetupTouched(cursedPart)
end)

so that’s how you use GetInstanceAddedSignal it worked pretty well thank you

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.