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

How would you make a ban function in a script?

Asked by
IcyEvil 260 Moderation Voter
8 years ago

Im trying to add a ban function to my holo commands(I released them on a different account) and I have some questions, first is how in general would this be performed(I have a sketch of something I think it would look like but its not very much) anyways, any help is greatly appreciated.

local admins ={"",}-- What Users(Needs to be EXACT)
local bans = {"ProphetCybrax"}
local gid = 0 -- What group THIS IS NEEDED
local gidranks = {0,0,0,0} -- What Ranks you want NEEDED
--Dont Mess with the Below --
--
function contains(list, element)
    for _, value in pairs(list) do
        if value == element then
            return true
        end
    end
end
game.Players.PlayerAdded:connect(function(Xd)
    if contains(bans, Xd.Name) then
        for _,i in pairs(bans)do
            if Xd.Name == i then
                Xd:Kick()
            end
        end
    end
end)
0
the sketch works by the way, I just want to know if this is a "Decent" way to perform this IcyEvil 260 — 8y
0
You need to be able to add players to the ban list in game, so do a player.Chatted(msg) function for it. But it looks good. TheDeadlyPanther 2460 — 8y
0
your not supposed to be able to ban people in game just yet, this is just a holo commands script. IcyEvil 260 — 8y
0
Well, I do not know any other ways to ban, other than :remove() (performed on the player). You have got it sorted :) If you need help making an in game ban command, refer to me :) TheDeadlyPanther 2460 — 8y

1 answer

Log in to vote
2
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

First, we need to detect things that are chatted. Let's look up the Chatted event on the wiki.

It redirected me here. Let's use that:

local admins ={} -- UserIds
local bannedPlayers = {} UserIds
local groupId = 0 -- What group THIS IS NEEDED
local minimumRanks = {0, 0, 0, 0} -- What Ranks you want NEEDED

checkRank = function(plrID)
    for a, admin in pairs(admins) do
        if admin == plrID then
            return true
        end
    end
    return false
end

game.Players.PlayerAdded:connect(function(player)
    if function( for a, v in pairs(bannedPlayers) do if v == player.UserId then return true end end return false end) then
    -- If the user is banned when they join, kick them
        player:Kick()
    end
    player.Chatted:connect(function(msg)
        if checkRank(player) then
            if msg:find("ban") then
                local banPlrName = msg:match("ban%s(.+)")

                for a, v in pairs(game.Players:GetPlayers()) do
                    if v.Name == banPlrName then
                        bannedPlayers[#bannedPlayers + 1] = v.UserId
                        v:Kick()
                    end
                end

            end
        end
    end)
end)
Ad

Answer this question