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

Ban System [closed]

Asked by
foxy83 15
11 years ago

I am having trouble making a ban System. What I mean is that I will be able to use ROBLOX studio and type in the players name and they are banned from the server.

Locked by FearMeIAmLag

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

5 answers

Log in to vote
3
Answered by
MrNicNac 855 Moderation Voter
11 years ago

Here's a way that uses indexes instead of table values. It makes searching for the name a lot faster. Don't worry about the =true; part and just copy the style.

01local BannedList = {
02    ["MrNicNac"] = true;
03    ["Lycan"] = true;
04    ["Shedletsky"] =true;
05}
06 
07function NewPlayer(pl)
08    if BannedList[pl.Name] then
09        wait()
10        pl:Kick();
11    end
12end
13 
14Game.Players.PlayerAdded:connect(NewPlayer)
15table.foreach(Game.Players:GetPlayers(), function(i,v) NewPlayer(v) end) -- Makes it function in solo mode
Ad
Log in to vote
5
Answered by
blocco 185
11 years ago

Something that neither of these answers capitalized upon is the use of the new and improved data stores. These data stores will provide you with a way to preserve your data across all servers, and it will update in real-time, so if they're banned from one server, they're immediately banned from all servers in that game.

Let's analyze the API dump for data stores:

01Class DataStoreService : Instance
02    Function Instance DataStoreService:GetDataStore(string name, string scope = global)
03    Function Instance DataStoreService:GetGlobalDataStore()
04 
05Class GlobalDataStore : Instance
06    Function Connection GlobalDataStore:OnUpdate(string key, Function callback)
07    YieldFunction Variant GlobalDataStore:GetAsync(string key)
08    YieldFunction Variant GlobalDataStore:IncrementAsync(string key, int delta = 1)
09    YieldFunction void GlobalDataStore:SetAsync(string key, Variant value)
10    YieldFunction Tuple GlobalDataStore:UpdateAsync(string key, Function transformFunction)

This API dump tells us what members the related objects have, and using these we can guess at how to use them. However, in some cases we won't be able to guess, or it would be better not to. In those cases, we just need to look for a guide on the wiki. What do you know? There is one! Now we know for sure how to use it.

Now that we have all the required components to create the solution to our problem, we can go forth and actually code it. Let's make a list of the things we want our solution to take care of:

  • Making a minimum list of banned players
  • Banning people on the fly for all servers
  • Unbanning people on the fly for all servers
01local DataStoreService = Game:GetService("DataStoreService")
02local persistentBannedList = DataStoreService:GetDataStore("PersistentBannedList")
03 
04-- this syntax is an alternate way to write
05-- data within tables, it still works though
06local minimumBannedList = {
07    ["PlayerX"] = true;
08    ["PlayerY"] = true;
09    ["PlayerZ"] = true;
10}
11 
12function isPlayerBanned(player)
13    return minimumBannedList[player.Name]
14        or persistentBannedList:GetAsync(player.Name)
15end
View all 27 lines...

Note that I have added an extra feature which requires a BindableFunction to be used properly. The BindableFunction object allows you to, from one script, call functions defined in another script. The API dump for this object is below too:

1Class BindableFunction : Instance
2    YieldFunction Tuple BindableFunction:Invoke(Tuple arguments)
3    Callback Tuple BindableFunction.OnInvoke(Tuple arguments)

Note that there is a caveat associated with this ban system. Users can change usernames. This is not an often occurence, but when it does happen, your ban system will not know, and it will allow them into your game. This is possible to fix, but if it is really necessary, you should be able to perform that fix.

Sources:

  • http://wiki.roblox.com/index.php?title=Class_reference/API_dump
  • http://wiki.roblox.com/index.php?title=Data_store
  • http://wiki.roblox.com/index.php?title=BindableFunction
Log in to vote
1
Answered by
bloxxyz 274 Moderation Voter
11 years ago

It would have been helpful if you provided a little more detail, but I think I understand. You want to type a player's name into a script and have them banned from the server. Try out this script, it's very simple and hopefully you can understand how it works:

01BannedPlayers = {"Player1", "Noob" }
02 
03 
04game.Players.PlayerAdded:connect(function(Player)
05    for i,v in pairs(BannedPlayers) do
06        if Player.Name == v then
07            Player:Destroy()
08        end
09    end
10end)

Alternatively, if you wanted to kick someone instead of simply destroying their character, you can also try this:

1game.Players.PlayerAdded:connect(function(Player)
2    if Player.Name == "Noob" then
3        Player:Kick()
4    end
5end)

*Side note, neither of these scripts will work in Solo mode, you must have a server opened.

Log in to vote
0
Answered by
Vividex 162
11 years ago
1game.Players.PlayerAdded:connect(function(plr)
2    if plr.Name == "PlayerName" then -- Replace "PlayerName" with Name
3        plr:kick()
4    end
5end)

Probably easiest way to do it

Log in to vote
-1
Answered by 11 years ago

Use some admin