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

Scripting a Kick system?

[[ - I Have a The Script, Sometimes It's Doesn't Work, Can You help me? - ]]

local MSG = "Banned." local Banlist = {

Example = true,

}

game.Players.PlayerAdded:Connect(function(plr) if Banlist[plr.Name] then plr:Kick(MSG) end end)

1 answer

You've got the right idea but it's better to loop through the table and check it's values.

local Players = game:GetService('Players')

local Banlist = {
	'noob123', -- username
	01234 -- user id
}

function checkBanlist(Player)
	for _,v in pairs(Banlist) do
		-- this will check for userid
		if type(v) == 'number' and v == Player.UserId then
			return true
		-- this will check for usernames
		elseif type(v) == 'string' and string.lower(v) == string.lower(Player.Name) then
			return true
		end -- check type
	end -- loop
	return false
end -- function end

function onPlayerAdded(Player)
	if checkBanlist(Player) then
		Player:Kick('innabit lad, ur banned') -- you can change this to any message
	end -- call function
end -- function end

Players.PlayerAdded:Connect(onPlayerAdded)

2 comments

0

shouldn't you use ipairs for the loop in the banlist?

0

I normally only use ipairs when I have a mixed table and need to scan through the numerical indices, which in this case isn't really needed.

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