Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

If player joined who is on whitelist, then kick?

Asked by 9 years ago

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.

01local WhiteList = script.Folder:GetChildren()
02local Defined = script.Folder.Defined.Value
03local Player = game.Players.PlayerAdded
04local A = script.Folder("1").Value
05local B = script.Folder("2").Value
06local C = script.Folder("3").Value
07local D = script.Folder("4").Value
08local E = script.Folder("5").Value
09game.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
16end)

For help, here is the model: http://www.roblox.com/THIS-IS-SPARTA-item?id=339927939

2
For the record, that's blacklist. ChemicalHex 979 — 9y
0
idc TheHospitalDev 1134 — 9y
0
What ChemicalHex said. minikitkat 687 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

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:

01local whitelist = script.Folder:GetChildren()
02 
03function WhiteListCheck(p)
04    for _,v in pairs (whitelist) do
05        if v.Value == p.Name then
06            return true
07        end
08    end
09end
10 
11game.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
16end)

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

01local whitelist = {
02    ["PlayerName"] = true,
03    ["PlayerName"] = true
04}
05 
06game.Players.PlayerAdded:connect(function(p)
07    if whitelist[p.Name] then
08        p:Kick("You are banned from this game")
09    end
10end)

This code just checks to see if the player is in the table, and if they are, they get kicked.

0
Thanks, I'm new to tables, etc.. TheHospitalDev 1134 — 9y
Ad
Log in to vote
0
Answered by 9 years ago
01local WhiteList = script.Folder:GetChildren()
02local Defined = script.Folder.Defined.Value
03local Player = game.Players.PlayerAdded
04local A = script.Folder("1").Value
05local B = script.Folder("2").Value
06local C = script.Folder("3").Value
07local D = script.Folder("4").Value
08local E = script.Folder("5").Value
09game.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
16end)

Now i may be totally wrong because im tired asf but, Try it . . .

0
Look, I could make you a much easier blocking script if you'ed like? CoffeeMesh 5 — 9y
0
Ok, Nvm Take this model it is the same script folder etc fixed ! let me know if it worked http://www.roblox.com/THiS-IS-SPARTA-Fixed-item?id=339949769 CoffeeMesh 5 — 9y

Answer this question