CollectionService for doors

So short said. I’m making a bunch of doors that have different settings and I want specifically on this door to fire for all staff personnel. The script works fine in a normal script and instead of

Door1.Part.ClickDetector

It would be

script.Parent.Part.ClickDetector

where as this works fine.
Now I put this in serverscriptservice and tagged everything as it should be tagged with StaffDoorR1 for specifying one type of rotation where as another StaffDoorR2 is for another rotation since doors rotate differently depending on where they are.

Right now I can’t get it to fire when I make a script and do this:

local CollectionService = game:GetService("CollectionService")
local Unauth = game.Teams.Patient.TeamColor
local Max = game.Teams["Max Security Patient"].TeamColor

for _,Door1 in pairs(CollectionService:GetTagged("StaffDoorR1")) do
	local Cooldown = 0
	local Knock = Door1.Center.Knock
	local Timer = Door1.Timer
Door1.Part.ClickDetector.MouseClick:Connect(function(Player)
	if Player.TeamColor == Unauth and Cooldown == 0 or Player.TeamColor == Max and Cooldown == 0 then
		Cooldown = 5
		Knock:Play()
		wait(2)
		Cooldown = 0
	elseif Player.TeamColor == Unauth and Cooldown == 5 or Player.TeamColor == Max and Cooldown == 5 then
		return
	else
	local Mag = (script.Parent.Center.Position-Player.Character.HumanoidRootPart.Position).magnitude
	if Mag <= script.Parent.Range.Value then
		if Can then
			Can = false
			if Open == false then
				local finish = script.Parent.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(90),0)
				for i = 0,1,.1 do
					local cfm = script.Parent.PrimaryPart.CFrame:lerp(finish,i)
					script.Parent:SetPrimaryPartCFrame(cfm)
					wait()
				end
				Open = true
				Timer.Value = 10
			else
				Open = false
				local finish = script.Parent.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(90),0)
				for i = 0,1,.1 do
					local cfm = script.Parent.PrimaryPart.CFrame:lerp(finish,i)
					script.Parent:SetPrimaryPartCFrame(cfm)
					wait()
				end
			end
			Can = true
		end
	end
	end
end)

while true do
	while Timer.Value > 0 do
		Timer.Value = Timer.Value - 1
		wait(1)
	end
	if Open == true and Timer.Value == 0 then
		Open = false
			local finish = script.Parent.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(90),0)
			for i = 0,1,.1 do
				local cfm = script.Parent.PrimaryPart.CFrame:lerp(finish,i)
				script.Parent:SetPrimaryPartCFrame(cfm)
				wait()
			end
			Can = true
	end
	wait()
end
end

The “unauth” and “max” is 2 teams that shouldn’t be allowed to use the door and instead makes a knock which has been working very fine with a normal script in the door.

There are different doors but they all fire the same way and I can’t make it work the way it should, can anyone help ?

What does each type of door do currently when on each team?

StaffDoors opens for anyone that is not on one of those:

local Unauth = game.Teams.Patient.TeamColor
local Max = game.Teams[“Max Security Patient”].TeamColor

I have other doors that opens and closes depending on a global value but it doesn’t really matter.

However the meaning of the doors doesn’t really matter as it works fine, the problem is how I can make it fire with collectionservice and clickdetectors.

So is your problem here in relation to the knocking sound effect? Does anything currently happen?

Nothing happens at all and I can’t make it fire.

The sound effects seem to work fine in my reproduction of this.

Do you have any errors? How are you tagging your doors with the collectionservice?

I’m using Sweetheartichoke’s tag editor.

They work fine and fires fine, it’s just the script I’m not sure of how to fix it.

Try using the following to tag your doors (be sure to edit ‘workspace.Doors’ as required)

for _,Door in pairs(workspace.Doors:GetChildren()) do
	CollectionService:AddTag(Door, "StaffDoorR1")
end

Although, if you were referring to the actual door movement instead of the sound effect the reason why this isn’t working is due to you referring to them as ‘script.Parent’, which would only work if the script was inside the door itself. Try changing all of these to ‘Door1’ and so on.

Additionally, you have an if statement which says

if Can then

However, Can is never actually initialized with a value. Creating a variable ‘Can’ with a value of true. This will rotate the door.

I think the reason is because the server script loads before the map.
Try doing this to add tags:

for _,v in pairs(workspace:WaitForChild("Doors"):GetChildren()) do
    CollectionService:AddTag(v, "StaffDoorR1")
end

If there’s something I’m not understanding, tell me.

Problem is I already did test the tags and they do fire whenever I do something that is simpler than this.

Hm. Try adding a ChildAdded to it then.

workspace:WaitForChild("Doors").ChildAdded:Connect(function(Child)
    CollectionService:AddTag(Child, "StaffDoorR1")
end)

Have you tried assigning a value to ‘Can’?

Where you give values to your variables also put

local Can = true