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
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