Simple Ban System

Hello!

I have a ban system to, well, ban people. I’m not sure if this a great system, but I will send it anyway. I was thinking of using a datastore or a module to do it, but I don’t really know if that’s necessary or not. Here’s the ban system:

	local Bans = {
		Case1 = {
				UserId = --[[pretend this is a user id]],
				Reason = "You have been permanently banned from the game for spreading rumours, spreading negativity, putting words in peoples mouths, being toxic, and more."
				},
		Case2 = {
				UserId = --[[pretend this is a user id]],
				Reason = "You have been permanently banned from the game for spreading rumours, spreading negativity, putting words in peoples mouths, being toxic, and more."
				},
		Case3 = {
				UserId = --[[pretend this is a user id]],
				Reason = "You have been permanently banned from the game for spreading rumours, spreading negativity, putting words in peoples mouths, being toxic, and more."
				},	
	}

	for i,v in pairs(Bans) do
		if plr.UserId == v.UserId then
			print(v.Reason)
			plr:Kick(i.." - "..v.Reason.." - UserId"..v.UserId)
		end
	end

Probably went overboard with the fake ban reasons, but yeah.

3 Likes

If you want a more flexible ban systen you could do something like what I did here:

1 Like

Will take a look, thanks! I’ll send a reply if I have any questions.

Is the one in the original post the final version?

Edit: Think I’d just go for a modulescript instead of a datastore, then require the asset each time a player joins. What do you think?

Your idea is good, however it would just last in one server. DataStore is one of the only ways to save ban logs, ensuring that players can no longer rejoin the entire game, rather than just a single server.

Personally, I like to set up my ban systems with DataStore. I typically use the same data store that handles all player data. Within the data that is stored, I use tables, of course, and inside I do the following:

local ExamplePlayerData = {
    Banned = {false,nil,nil,nil,nil}
     -- Other data variables
}

The first bool value you see, represents if the player is banned or not. It should default at false, unless you have a premade ban list featuring players who have yet to play the game. I am sure you can figure all that out.

Regardless of order, the remaining four values represent: Ban reason, admin who banned, time banned, and time when they become unbanned.

Now, I set the values based off of what the admin inputs. I have a system in my game where it translates a string to a value of time. For example, “2d” = 2 days, “8h” = 8 hours, and so on and so forth. Using this value, the ban time is set to tick(), and the unban time is set to tick() plus the time that was calculated (in seconds).

Once the data is set, the player should be kicked from the game, with the message stating: "Kicked by “…AdminName (set up with the saved values)… " for “…Reason (again, link to values)…”.”

Every time a player joins my game, it first checks if they are banned. If the first value is set to false, then it passes through and loads data as normal. However, if it is set to true, it scans the second, thrid, fourth, and fifth values. It checks if the current time os.time() is greater (>) than the unban time. If so, it resets the data, defaulting at {false,nil,nil,nil,nil}. If the time has not yet passed, it kicks them again with the same message as stated before.

Why go to this length would you ask? Well, you could always use free admin sources in your game. HD admin is one of the better. However, I prefer my own code, preventing random commands from being enabled into my games. With this system, you can set how long a player is banned and state a reason.

This system is not necessarily simple by any means, however it is very effective and has lots of customization features included.

Thanks for reading. I hope this helps. Have a great day!

  • Galactiq
5 Likes

I’m not exactly sure what you mean there, but the script I made in that post is mainly ab example as to how a datastore ban system would work. You can go even more out on your ban script but if your game isn’t controlled by a major group I don’t think you would need a whole web system.

This would be a really bad idea, bad practice.

if you want a more complex ban store you could of cores go with what @Galactiq said.

1 Like

To @Galactiq too:
Think I’d go with a datastore ban system then, as it seems like the optimal reason, however I’m not really sure how I would go about banning players. 'Think an admin panel would work? I saw it as a reply on your post.

Probably could go and change the datastore there. Also thinking that’s the best reason as I can add more customization as I get better at scripting.

And yeah, a free admin model isn’t really optimal considering I believe I have the skills of making my own.

Also, the admin who banned you is a great idea, think I will implement that.

Thank you two for your input!

Depending on your standard you could make the ban system based on what a player says in chat or within a panel, or both.

1 Like

I think a panel would be optimal as I personally think bans shouldn’t really be anyone’s business aside from the moderation team, and the person who was banned.

Typically I use chat commands for banning and kicking purposes. I usually set it up where it takes all of the arguments and decides if the first is an id or a player name. Then, it gets the UserId, and then alters the data store from there. The following arguments should be the time length of the ban and/or a reason. I usually put the reason as the last argument so you can piece together multiple arguments, if the parse function declares there are more than 2 arguments.

1 Like

A panel could be accomplished with RemoteEvents, requiring server checks. However, you can easily modify the default roblox chat system, or use your own, to prevent certain messages from being displayed in the chat. For example, deny strings starting with “/”, or if you wanted to make it more specific, iterate through a table of all commands, and make sure the message doesn’t match one of the commands.

1 Like

Probably going to do a panel then.

Not really sure how you’d decide between if it’s a username or a user’s ID but that’s pretty smart. I think I’d have the panel give the option between a username and an ID.

:SetAsync is probably really useful in this situation haha.

Plus seems like less amount of work for the same thing.

You can do a simple check on the first argument if it is an id or username by the following:

if type(tonumber(Argument)) == "number" then 
     -- Code here
end

Another simple way is:

if tonumber(Argument) then
     -- Code here
end

There are many small checks that can make a system very optimal and easy to use for admins.

To answer your previous reply: Yes, you would use SetAsync. And yes, if you do not care for storing a time length or reason for a ban, you can use just a simple bool value.

1 Like

Yeah, I’m not too flexible on bans. I’ll probably give an option to appeal as well.

These are possible; although some usernames are just numbers, which could also be a UserID, so perhaps not the best way. Could use

if tonumber(Arg) and game.Players:GetNameFromUserIdAsync(tonumber(Arg)) and not game.Players:FindFirstChild(Arg) then

end
1 Like

You are correct. If the OP decides to use the user Id as an argument, this method is great in detecting if it is a player name or user id. Thanks, @iiRealistic_Dev .

2 Likes

Problem with this is that if the moderator joins a server, and the player isn’t there, they won’t be able to ban them.

Probably will just go with my original idea and give the option between banning the username or the user ID

Use elses; the and not means if they’re not in game, e.g:

if tonumber(Arg) and game.Players:GetNameFromUserIdAsync(tonumber(Arg)) and not game.Players:FindFirstChild(Arg) then
    -- most likely not in-game
elseif game.Players:FindFirstChild(Arg) then
    -- is in game
end

Of course giving the option is probably a little more reliable, just saying how you could do this

Oh right, okay. I will put some time into thinking about this. Thank you for the ideas.

1 Like