This script is supposed to allow the players with the ids in the table to join the game without getting kicked and having their chat removed. If their ID isn't in that table then they are supposed to be kicked and have their chat removed. However, when this is in my game, it kicks everyone who joins even the players with the IDs and it doesn't remove their chat. Please can someone help me?
local ids={14946581,-1,0,1}
game.Players.PlayerAdded:connect(function(plr)
local it = false
for _,v in pairs(ids) do
if plr.UserId==v then
local it=true
end
end
if it==false then
game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
wait(.1)
plr:Kick("You do not have permission to join this game.")
end
end)

1 comment
you define a new variable in the scope of the for loop and set it to true, the "it" variable in the player function scope is still false so it will kick all players.