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

Scripting a Kick system?

Asked by 3 years ago

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

Log in to vote
0
Answered by
pwx 1581 Moderation Voter
3 years ago

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)
0
shouldn't you use ipairs for the loop in the banlist? 0hsa 193 — 3y
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. pwx 1581 — 3y
Ad

Answer this question