Hello fellow developers! I was once trying to make a custom admin system. But, I never knew how to start/make it. If you are trying to make a custom admin system, hopefully this tutorial will help you and not make you stuck in the position I was in.
Step 1
Setup
First, make a script in ServerScriptService. Name it however you’d like. I am going to name it Admin.
Step 2
Essentials
I am going to place the important variables we need at the top of our script.
local Players = game:GetService('Players');
local Prefix = ':'; -- What goes in front of every command that is ran
local Admins = {};
The admins table will be used to place the username or userID of those who are allowed to run the commands.
Step 3
Scripting
Now comes the fun part! The actual scripting. Make sure to follow exactly how I have it.
First, we are going to create a function that makes sure the person that runs the command is an admin.
function CheckIfAdmin(plr)
for i = 1, #Admins do
if Admins[i] == plr.UserId or Admins[i] == plr.Name then
return true;
end
end
return false;
end
Now, we are going to make the command handler.
Players.PlayerAdded:Connect(function(p)
p.Chatted:Connect(function(m)
local args = string.split(m, ' ');
if string.lower(args[1]) == Prefix..'test' then
if CheckIfAdmin(p) == true then
print('Works!');
end
end
end)
end)
- string.split() makes the command into an table like this {’:test’, ‘e’}.
- string.lower() makes the first argument lowercase to check if it’s a command so it can check if it’s like ‘:tEsT’ or ‘:TEST’ or however you run it.
Of course you can add more commands, but use the elseif function, like this.
Players.PlayerAdded:Connect(function(p)
p.Chatted:Connect(function(m)
local args = string.split(m, ' ');
if string.lower(args[1]) == Prefix..'test' then
if CheckIfAdmin(p) == true then
print('Test Works!');
end
elseif string.lower(args[1]) == Prefix..'test2' then
if CheckIfAdmin(p) == true then
print('Test 2 works!');
end
end
end)
end)
Also, this simple admin system does support GUIs. I will show a quick example.
elseif string.lower(args[1]) == Prefix..'message' then
if args[1] then
table.remove(args,1);
local message = game.Chat:FilterStringForBroadcast(table.concat(args, ' '));
if message then
local UI = Instance.new('Message');
UI.Parent = workspace;
UI.Text = p.Name..': '..message;
wait(6);
UI:Destroy();
end
end
end
It makes the standard ROBLOX message GUI and shows the message to everybody in the server.
- Instance.new() makes a new object such as a message UI, hint UI, part, etc.
- table.concat() makes all arguments together. For example: {’:message’, ‘test’} → ‘:message test’
FULL CODE
local Players = game:GetService('Players');
local Prefix = ':'; -- What goes in front of every command that is ran
local Admins = {game.CreatorId};
function CheckIfAdmin(plr)
for i = 1, #Admins do
if Admins[i] == plr.UserId or Admins[i] == plr.Name then
return true;
end
end
return false;
end
Players.PlayerAdded:Connect(function(p)
p.Chatted:Connect(function(m)
local args = string.split(m, ' ');
if string.lower(args[1]) == Prefix..'test' then
if CheckIfAdmin(p) == true then
print('Test Works!');
end
elseif string.lower(args[1]) == Prefix..'test2' then
if CheckIfAdmin(p) == true then
print('Test 2 works!');
end
elseif string.lower(args[1]) == Prefix..'message' then
if args[1] then
table.remove(args,1);
local message = game.Chat:FilterStringForBroadcast(table.concat(args, ' '), p);
if message then
local UI = Instance.new('Message');
UI.Parent = workspace;
UI.Text = p.Name..': '..message;
wait(6);
UI:Destroy();
end
end
end
end)
end)
I will be making an advanced admin system tutorial soon. Let me know if this tutorial helped!