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 8 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.

local WhiteList = script.Folder:GetChildren()
local Defined = script.Folder.Defined.Value
local Player = game.Players.PlayerAdded
local A = script.Folder("1").Value
local B = script.Folder("2").Value
local C = script.Folder("3").Value
local D = script.Folder("4").Value
local E = script.Folder("5").Value
game.Players.PlayerAdded:connect(function()
    if Player == Defined then
    game.Players(Player):Kick("Go away, you have no friends...")
    print("Player Attempted to join!")
    elseif Player.Name == A or B or C or D or E then
    game.Players(Player):Kick("Bai!")
    end
end)

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 — 8y
0
idc TheHospitalDev 1134 — 8y
0
What ChemicalHex said. minikitkat 687 — 8y

2 answers

Log in to vote
1
Answered by 8 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:

local whitelist = script.Folder:GetChildren()

function WhiteListCheck(p)
    for _,v in pairs (whitelist) do
        if v.Value == p.Name then
            return true
        end
    end
end

game.Players.PlayerAdded:connect(function(p)
    local banned = WhiteListCheck(p)
    if banned == true then
        p:Kick("You are banned from this game")
    end
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

local whitelist = {
    ["PlayerName"] = true,
    ["PlayerName"] = true
}

game.Players.PlayerAdded:connect(function(p)
    if whitelist[p.Name] then
        p:Kick("You are banned from this game")
    end
end)

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 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
local WhiteList = script.Folder:GetChildren()
local Defined = script.Folder.Defined.Value
local Player = game.Players.PlayerAdded
local A = script.Folder("1").Value
local B = script.Folder("2").Value
local C = script.Folder("3").Value
local D = script.Folder("4").Value
local E = script.Folder("5").Value
game.Players.PlayerAdded:connect(function()
    if Player.Name == Defined then -- Try Player.Name
    game.Players(Player):Kick("Go away, you have no friends...") -- lol 
    print("Player Attempted to join!")
    elseif Player.Name == A or B or C or D or E then
    game.Players(Player):Kick("Bai!")
    end
end)

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 — 8y
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 — 8y

Answer this question