[[ - 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)
[[ - 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)
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
shouldn't you use ipairs for the loop in the banlist?
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.