Collection Service Not Working, Not Firing Touched Event

So basically I wanted to create a script for Doors to open when a player is close to them. I found a tutorial on Collection Service but when I used the touched event on a part in my Model it doesn’t print(“Hello!”).

local distanceModule = require(game.ServerScriptService.doorHandlers.getDistance)
local doorFolder = game.Workspace.castleDoors:GetChildren()
local collectionService = game:GetService("CollectionService")

for _, model in ipairs(doorFolder) do
	local currentTag = 1
	collectionService:AddTag(model.Union, "doorUnions")
	currentTag += 1
end

for _, part in pairs(collectionService:GetTagged("doorUnions")) do
	part.Touched:Connect(function()
		print("Hello!")
	end)
end

Screenshot_24

This is the order of the Folder.

Screenshot_25

This is the order in a Door model.

Already thanks in advance for helping!

2 Likes

Is this serversided or client sided?

This is a Server Script, in Server Script Service.

Try this, also keep in mind touched might not work properly for unions

local distanceModule = require(game.ServerScriptService.doorHandlers.getDistance)
local doorFolder = game.Workspace.castleDoors
local collectionService = game:GetService("CollectionService")

local currentTag = 1
for _, model in ipairs(doorFolder:GetChildren()) do
	collectionService:AddTag(model.Union, "doorUnions")
	currentTag += 1
end

for _, part in pairs(collectionService:GetTagged("doorUnions")) do
	part.Touched:Connect(function()
		print("Hello!")
	end)
end

I’m not sure if I’m right, but you can’t do touched event on models, you have to do it on parts, maybe try doing it on your primarypart?

1 Like

I fixed it myself, apparently canTouch property is off by default on Unions.

1 Like

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