Spectate script assistance

Hi, below I have a simple script that lets a player spectate when they press an ImageButton on the screen.

I have a few teams set up, and I would like to adapt the script so that the image button can only be clicked to bring up the spectate screen only when the player is in the Lobby Team (other teams can’t access the spectate menu). I tried implementing a simple if statement to try and implement this however it didn’t seem to work and I am not sure why. (Didn’t include that edited version to make it clearer how the basic script looks as is). Additionally I was trying to make it so that the imagebutton wasn’t visible to any team other than the Lobby team.

Could anyone point me in the right direction or suggest some syntax to possibly get this working?
Thanks in advance

local spectateFrame = script.Parent.SpectateFrame
local button = script.Parent.Frame.ImageButton
local openNow = true
local position = 1 -- New variable!
local playerList = {}
local cam = workspace.CurrentCamera -- Camera variable!
local function updatePlayerList(exemptPlayer) -- This player won't be added in, if specified
	for _, plr in pairs(game.Players:GetPlayers()) do
		if plr ~= exemptPlayer and not table.find(playerList, plr) then -- If the player isn't exempt and not in it already, add them in!
			table.insert(playerList, plr)
		end
	end
end
local function updateCamera(playerSubject) -- New function! This will change the camera view to whatever player is given for the function!
	pcall(function() -- To make sure it doesn't throw an error.
		spectateFrame.TextLabel.Text = tostring(playerSubject)
		cam.CameraSubject = playerSubject.Character
	end)
end

updatePlayerList() -- We'll update it right away, then when a player leaves/joins
game.Players.PlayerAdded:Connect(function()
	updatePlayerList()
end)
game.Players.PlayerRemoving:Connect(function(player)
	updatePlayerList(player)
end)

button.MouseButton1Click:Connect(function()
	if openNow then
		openNow = false
		spectateFrame.Visible = true
		position = 1 -- We're gonna set it to the first player in the table when they open up spectate!
		updateCamera(playerList[1])
	else
		openNow = true
		spectateFrame.Visible = false
		updateCamera(game.Players.LocalPlayer) -- Adding it to close
	end
end)
spectateFrame.LeftButton.MouseButton1Click:Connect(function()
	position = position - 1
	if position < 1 then
		position = #playerList -- Change position to last on the list
	end
	updateCamera(playerList[position]) -- Changes camera to person on the list
end)
spectateFrame.RightButton.MouseButton1Click:Connect(function()
	position = position + 1
	if position > #playerList then
		position = 1 -- Change position to last on the list
	end
	updateCamera(playerList[position]) -- Changes camera to person on the list
end)
spectateFrame.StopButton.MouseButton1Click:Connect(function()
	openNow = true
	spectateFrame.Visible = false
	updateCamera(game.Players.LocalPlayer) -- Adding it to close so we can change back our camera!
end)

Correct me if i’m wrong but you are trying to make it so the gui can be accessed ONLY when they are on the lobby team?

Yeah so the imagebutton that is pressed to bring up the spectate mode, I was trying to make it so the image button is only available on your screen when you are on the lobby team (I suppose this would also solve the issue of other teams being able to click the button, as they wouldnt be able to see it).
However a simple if statement didnt seem to work for me so I must have done something wrong with the syntax?

You could just check when someone leaves the team, and if your “localplayer” is the one that left the team than make the screen invisible, if you joined the team than make it so the button is visible