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:
01 | Class DataStoreService : Instance |
02 | Function Instance DataStoreService:GetDataStore(string name, string scope = global) |
03 | Function Instance DataStoreService:GetGlobalDataStore() |
05 | Class 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
01 | local DataStoreService = Game:GetService( "DataStoreService" ) |
02 | local persistentBannedList = DataStoreService:GetDataStore( "PersistentBannedList" ) |
06 | local minimumBannedList = { |
12 | function isPlayerBanned(player) |
13 | return minimumBannedList [ player.Name ] |
14 | or persistentBannedList:GetAsync(player.Name) |
16 | function setBanStatus(player, status) |
17 | minimumBannedList [ player.Name ] = status |
18 | persistentBannedList:SetAsync(player.Name, status) |
20 | script.SetBanStatus.OnInvoke = setBanStatus |
22 | function onPlayerAdded(player) |
23 | if isPlayerBanned(player) then |
27 | Game:GetService( "Players" ).PlayerAdded:connect(onPlayerAdded) |
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:
1 | Class 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
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?