Configurable Admin System

Hello everyone, today I will be doing a tutorial on how to make a configurable admin system! This will allow you to create you own commands that can do whatever you want (You have to script it) and they also take in arguments from the command that you can use. Without any further to do, let’s get right into it!

Step 1: Create Script and Variables

First off, you will want to create a Script in Workspace and you can call it whatever you like. After that you have to create the variables which is fairly simple. Just change these variables to how you like.

local Admins = {231214541,12345678} -- Change this to all the Player Admins' User Ids
local prefix = "!" -- The Command Prefix you would like to use

Step 2: Functions

After creating the variables, you can now write the code to make this work. We must create functions to make it able for commands to work.

game.Players.PlayerAdded:Connect(function(Player)
	-- Checks if player is an admin
	if table.find(Admins,Player.UserId) then
		print(Player.Name.." is an Admin!")
		
		Player.Chatted:Connect(function(Message)
			-- This is where the commands will happen
		end)
	end
end)

Step 3: Making Commands Work

Now that the functions are created, you can now make it so it gets the command’s arguments and things happen when commands are used! First, we have to check if the message starts with the prefix. Put this code inside the Player.Chatted Function:

if string.sub(Message,1,string.len(prefix)) == prefix then
	-- This is a command
end

Now that the script is able to detect if the message is a command or not, if the message is a command, then it has to check for the arguments, so now add this code into the if statement:

local Arguments = string.split(Message," ")
local Command = string.lower(string.sub(Arguments[1],2,string.len(Arguments[1])))
table.remove(Arguments,1)

Now that we have the Command and it’s arguments, we can now create a command! This is an example of a very basic command (Add this code under the code you typed previously):

if Command == "print" then
	print(Arguments[1])
end

Final Notes:

If you “Got Lost”, which could be very easy for some people, here is the whole code:

local Admins = {231214541,12345678} -- Change this to all the Player Admins' User Ids
local prefix = "!"

game.Players.PlayerAdded:Connect(function(Player)
	-- Checks if player is an admin
	if table.find(Admins,Player.UserId) then
		print(Player.Name.." is an Admin!")
		
		Player.Chatted:Connect(function(Message)
			
			if string.sub(Message,1,1) == prefix then
				--	Get Command/Arguments
				local Arguments = string.split(Message," ")
				local Command = string.sub(Arguments[1],2,string.len(Arguments[1]))
				table.remove(Arguments,1)
				
				-- Command Template
				if Command == "print" then
					print(Arguments[1])
				end
			end
		end)
	end
end)

Arguments will be a table with all arguments stated after the command.
E.g.: If the message was “!say Hi Hello”, Arguments[1] would be “Hi” and Arguments[2] would be “Hello”

Any other comments/questions? Just reply down below!
Also make sure to leave a reply down below to show me what amazing commands you were able to create!
Thanks for reading and I hope this tutorial will help you! :smile:

30 Likes

Hey!
So, how would i make a kick command with a custom kick message to that player?
I tried making it, but when i typed this command:

"!kick testsubject Your Kicked.

Its kick message would be:

“Your”

While it would be easy to change knowing how to change it, why did you choose to have a String table for admins (the player’s name) rather than using UserIds when players could change their name?

Hey! This problem is easily fixable. First, you must remove Arguments[1] by doing table.remove(Arguments,1). After that, you have to create a variable (Whatever name) and assign it to table.concat(Arguments," "). Use this variable as the kick message and it should kick with the whole message. Hope this helped!

Oh, I haven’t thought of that, thanks for the comment, I can fix that!

Can you show me where to place the new arguments?

script:

local Admins = {"TheEmeraIdDev"} -- Change this to all the Player Admins (Case Sensitive)
local prefix = "!"

game.Players.PlayerAdded:Connect(function(Player)
	-- Checks if player is an admin
	if table.find(Admins,Player.Name) then
		print(Player.Name.." is an Admin!")
		
		Player.Chatted:Connect(function(Message)
			
			if string.sub(Message,1,1) == prefix then
				--	Get Command/Arguments
				local Arguments = string.split(Message," ")
				local Command = string.sub(Arguments[1],2,string.len(Arguments[1]))
				table.remove(Arguments,1)
				
				-- Command Template
				if Command == "kick" then
					game.Players[Arguments[1]]:Kick(Arguments[2])
				end
			end
		end)
	end
end)

You could do something similar to this.

if command == "kick" then
    local plr = Arguments[1]
    table.remove(Arguments, 1)
    local message = string.concat(Arguments, " ")
    game.Players:FindFirstChild(plr):Kick(message)
end

Here is the fix:

local Admins = {407480830}
local prefix = "!"

game.Players.PlayerAdded:Connect(function(Player)
	-- Checks if player is an admin
	if table.find(Admins,Player.UserId) then
		print(Player.Name.." is an Admin!")
		
		Player.Chatted:Connect(function(Message)
			
			if string.sub(Message,1,1) == prefix then
				--	Get Command/Arguments
				local Arguments = string.split(Message," ")
				local Command = string.sub(Arguments[1],2,string.len(Arguments[1]))
				table.remove(Arguments,1)
				
				-- Command Template
				if Command == "kick" then
					local TargetPlayer = game.Players[Arguments[1]]
					table.remove(Arguments,1)
					local KickMessage = table.concat(Arguments," ")
					TargetPlayer:Kick(KickMessage)
				end
			end
		end)
	end
end)

Please tell me if there was a problem!

1 Like

Worked Perfectly! Thank you so much (ive been tryna add a custom admin into my game as i dont like regular types of admin.)

Yes, that is true, however there is no such thing as string.concat(), there is only table.concat()

Yeah I realized that after but I’m on my phone so it’s difficult enough already to type code.

No problem, hope this will be useful for you!

BTW, do you have a dizzy? I was wondering if i could add you!

Yes, I do! You can add me at BuilderDolphin#9422.

Added! Again, tysm for helping me, this means alot!

This tutorial really helped me, I wanted to make a admin system but I couldn’t make one but this one helped me a lot. I made a lot of commands like: give money, kill all, kill, spawn object, kick. But I have a slight problem, how can I make a ban/unban command. The ban command is easy, I can just add a value called banned to the player and save it using datastores. And a script will check when a player joins that the player has banned value and if it has it will kick it. But how can I unban someone. Changing the value back to false won’t work because the player isn’t in game. Or should I use a different banning method?

When unbanning somebody, just make it so that it gets the UserId of the player and sets the DataStore value banned value to false (Using UserId as key or in key). Also, you do not have to add a value to the player, you can just save the value true in the DataStore and when the player joins, if the DataStore value is true, then kick them.

Ok, I will try doing that and also

I said that I did the ban system like that. But thanks for the help!

It’s a really good system and helps alot!