✓ Accepted answer
##Problem
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.
##Solution
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.
##Final Script
AlphaTesters = {"Player1", "BeafBomber", "Sxult"}
function IsAnAlphaTester(Player)
for _,v in pairs(AlphaTesters) do
if v:lower() == Player.Name:lower() then
return true
end
end
return false
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)
##Credit Due
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.
######Hopefully this answered your question. If it did, do not forget to hit the accept answer button. If you have any questions, feel free to comment below and I will get back to you.
8 comments
Oops, my answer was wrong wasn't it xD
Does this need to be a local script or a normal script? Whenever I do a normal script it errors.
Needs to be a server script, what's the error?
No errors. It is a server script in ServerScriptStorage
Well, what's the problem? How are you testing it? Are you in Studio Test mode or in an actual server testing this script?
Actual testing in the server. I use f9 for console
Did you check the Server Logs tab? Are you getting kicked? Try printing some lines to see if the Kick command processes or not. You could wait for the Character to load by adding newPlayer.CharacterAdded:wait() before the if then statement.
Ah it works now