Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

If player joined who is on whitelist, then kick?

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

3 comments

2

For the record, that's blacklist.

0

idc

0

What ChemicalHex said.

2 answers

✓ Accepted answer

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.

1 comment

0

Thanks, I'm new to tables, etc..

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

2 comments

0

Look, I could make you a much easier blocking script if you'ed like?

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

This discussion is preserved as it was. New answers, comments, and votes are closed.