I have done literally everything and I still cannot figure out why this doesnt work. I am trying to make it so that when a player clicks a button it will search through the table and if their name is found then the variable is true. However the GUI never ends up enabling, except for when I put my name in place of "player2". It only works if my name is the on last array, I have tried ipairs and in pairs, any help appreciated.
local Label = script.Parent
local CanOpen = false
local GUIOpened = false
local Player = game.Players.LocalPlayer
local UmpireTable = {"player1", "FriendBandsX", "player2"}
function InitiateGame(A)
if A == true then
if GUIOpened == false then
Player.PlayerGui:WaitForChild("ControlGUI").Enabled = true
GUIOpened = true
elseif GUIOpened == true then
Player.PlayerGui:WaitForChild("ControlGUI").Enabled = false
GUIOpened = false
end
else
return
end
end
Label.MouseButton1Click:Connect(function()
for i, v in pairs(UmpireTable) do
print(v)
if v == Player.Name then
CanOpen = true
end
end
InitiateGame(CanOpen)
end)

5 comments
I put this code in studio and it works just fine?
Use if table.find(UmpireTable, Player.Name) then instead
but the code works, im rlly confused
Code looks okay, but like KingFruitBox365 said use table.find as it's way better than making a cycle for that
is it though? i feel like its still looping through the array in the background