(Gate scripting)

So I need helped so I currently making a Gate I want to make sure it can be locked so they can just click on it and then it opens for that team?
I am currently trying to find out how do i solve this problem i never script but if Myself can get help i would love it!


CONTACT
SouthWestInfantry#5980 if needed

Make a hitbox for it with a click detector

then run a function through that using this

script.Parent.MouseClick:Connect(function()
--function here
end)
-- This is an example Lua code block

Okay so their a script in the Gate would it make it little visible but only That team can open it?

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

script.Parent.MouseClick:Connect(function(clicker)
for _, v in pairs(Players:GetChildren()) do
       if v == clicker then
           if v.Team == Teams["team name"] then
         -- open script
            end
      end
end)