Team Clickdetector Gate

Hey could anyone tell me how this script works so that only one team can open.

Here the Script

local isOn = true

function on()
	isOn = true
	script.Parent.Tur1.CanCollide = true
	script.Parent.Tur1.Transparency = 0
	script.Parent.Tur1.ClickDetector.MaxActivationDistance = 20
	script.Parent.Tur2.CanCollide = false
	script.Parent.Tur2.Transparency = 1
	script.Parent.Tur2.ClickDetector.MaxActivationDistance = 0
	script.Parent.Tur3.CanCollide = true
	script.Parent.Tur3.Transparency = 1
	script.Parent.Tur4.CanCollide = false
	script.Parent.Tur4.Transparency = 1
end

function off()
	isOn = false
	script.Parent.Tur1.CanCollide = false
	script.Parent.Tur1.Transparency = 1
	script.Parent.Tur1.ClickDetector.MaxActivationDistance = 0
	script.Parent.Tur2.CanCollide = true
	script.Parent.Tur2.Transparency = 0
	script.Parent.Tur2.ClickDetector.MaxActivationDistance = 20
	script.Parent.Tur3.CanCollide = false
	script.Parent.Tur3.Transparency = 1
	script.Parent.Tur4.CanCollide = true
	script.Parent.Tur4.Transparency = 1
end

function onClicked()
	
	if isOn == true then off() else on() end

end

script.Parent.Tur1.ClickDetector.MouseClick:connect(onClicked)
script.Parent.Tur2.ClickDetector.MouseClick:connect(onClicked)

on()

I look forward to help.

I won’t implement with your exact code but here’s a simple script to escape a ClickDetector connection based on the players’ team:

local teamWithAccess = game:GetService("Teams"):WaitForChild("TeamName")
--change TeamName to the team you want to have access to the button

local clickDetector = script.Parent:WaitForChild("ClickDetector")

clickDetector.MouseClick:connect(function(ply)
	if ply.Team ~= teamWithAccess then return end
    --If the player isn't on the correct team, the function exits 
    --here and the rest won't run

	print("access granted :-)")--only prints if they are on correct team
end)
if player.Team == game:GetService("Teams").YourTeamHere then

end
function onClicked(player)
   if player.Team == game:GetService("Teams"):FindFirstChild("Team") then
     if isOn then off() else on() end
end

script.Parent.Tur1.ClickDetector.MouseClick:Connect(onClicked(player))
script.parent.Tur2.ClickDetector.MouseClick:Connect(onClicked(player))