So, I have a script that is meant to function when a Player is added. Once fired, it checks if that player's name equals one of the values inside of a folder inside of the script. If it matches, it then kicks the player and displays a custom message, but it doesn't function, and I can't find out why.
01 | local WhiteList = script.Folder:GetChildren() |
02 | local Defined = script.Folder.Defined.Value |
03 | local Player = game.Players.PlayerAdded |
04 | local A = script.Folder( "1" ).Value |
05 | local B = script.Folder( "2" ).Value |
06 | local C = script.Folder( "3" ).Value |
07 | local D = script.Folder( "4" ).Value |
08 | local E = script.Folder( "5" ).Value |
09 | game.Players.PlayerAdded:connect( function () |
10 | if Player = = Defined then |
11 | game.Players(Player):Kick( "Go away, you have no friends..." ) |
12 | print ( "Player Attempted to join!" ) |
13 | elseif Player.Name = = A or B or C or D or E then |
14 | game.Players(Player):Kick( "Bai!" ) |
15 | end |
16 | end ) |
For help, here is the model: http://www.roblox.com/THIS-IS-SPARTA-item?id=339927939
Now, I am going to completely redesign your script, the first being an improvement of your one, and the second being a new (but much more efficient) way to do it.
Redesign #1:
01 | local whitelist = script.Folder:GetChildren() |
02 |
03 | function WhiteListCheck(p) |
04 | for _,v in pairs (whitelist) do |
05 | if v.Value = = p.Name then |
06 | return true |
07 | end |
08 | end |
09 | end |
10 |
11 | game.Players.PlayerAdded:connect( function (p) |
12 | local banned = WhiteListCheck(p) |
13 | if banned = = true then |
14 | p:Kick( "You are banned from this game" ) |
15 | end |
16 | end ) |
This code cycles through all of the the children of whitelist, checking to see if their value is the Player's name. If it is, it returns true, and the PlayerAdded function kicks them.
Redesign #2
01 | local whitelist = { |
02 | [ "PlayerName" ] = true , |
03 | [ "PlayerName" ] = true |
04 | } |
05 |
06 | game.Players.PlayerAdded:connect( function (p) |
07 | if whitelist [ p.Name ] then |
08 | p:Kick( "You are banned from this game" ) |
09 | end |
10 | end ) |
This code just checks to see if the player is in the table, and if they are, they get kicked.
01 | local WhiteList = script.Folder:GetChildren() |
02 | local Defined = script.Folder.Defined.Value |
03 | local Player = game.Players.PlayerAdded |
04 | local A = script.Folder( "1" ).Value |
05 | local B = script.Folder( "2" ).Value |
06 | local C = script.Folder( "3" ).Value |
07 | local D = script.Folder( "4" ).Value |
08 | local E = script.Folder( "5" ).Value |
09 | game.Players.PlayerAdded:connect( function () |
10 | if Player.Name = = Defined then -- Try Player.Name |
11 | game.Players(Player):Kick( "Go away, you have no friends..." ) -- lol |
12 | print ( "Player Attempted to join!" ) |
13 | elseif Player.Name = = A or B or C or D or E then |
14 | game.Players(Player):Kick( "Bai!" ) |
15 | end |
16 | end ) |
Now i may be totally wrong because im tired asf but, Try it . . .