This is a local script inside of starter gui
AlphaTesters = {"Player1", "BeafBomber", "Sxult"} game.Players.PlayerAdded:connect(function(newPlayer) for i,v in pairs(AlphaTesters) do if v.Name == newPlayer then print('Person with access joined') else v:Kick("Sorry, this game is in closed Alpha".."\n".."Only Developers/Alpha testers may enter") end end end)
Right now the game is in alpha and I only want testers/developers to join. I made this script to prevent people. Strangely when I first made it, it worked. Then at a random moment it broke. (Probably studio crashed and I didn't see the change qq)
P.S, I didn't add my name so I could test it myself.
Thanks.
What is happening is when the first player joins the game, they have to have the name Player1. Otherwise they will get kicked no matter what.
Because the for loop will go into an if then statement which will check, alright so the player's name is not Player1, kick him. Oh the player's name was "BeafBomber", oh well he was already kicked since we were asked.
You can do what many admin scripts do. Call a function that will go through the for loop and return true if the name is correct, or return false once the for loop terminates.
AlphaTesters = {"Player1", "BeafBomber", "Sxult"} function IsAnAlphaTester(Player) for _,v in pairs(AlphaTesters) do if v:lower() == Player.Name:lower() then --:lower() will make the entire name or string lowercase, as to not be worried on case sensitivity. return true --At this point, we know the player's name is in the list, so we will tell whoever called the function the good news. end end return false --If the player's name was not found by now, it never will... end game.Players.PlayerAdded:connect(function(newPlayer) if IsAnAlphaTester(newPlayer) then print('He is testing the game.') else newPlayer:Kick('Sorry, game is in closed alpha testing. Try again later.') end end)
wfvj014 ended up mentioning this, you were getting your variables mixed up because you tried to kick a string value "v". Not the "newPlayer" who kick was supposed to be called on. Good catch wfvj014!
BStandsForBuilding mentioned this as well. Kick will not work as intended in a LocalScript. Same with the PlayerAdded event in StarterGui, you need to move the script to a Server Script and you will need to move the script to ServerScriptService or Workspace.