A very basic admin system

What is this?


This is a very basic and simple admin system for people looking for the most basic admin system.
You are not able to admin people within the game, or perm ban anyone. This is very non-abusive, mainly for people looking for strict moderation systems, and for people looking to learn on how to start making their own admin system.

Features: (Very bare bone haha)


  • Able to create custom commands within the commands module.

Source:


Server-Script:

-- # Services
local Players = game:GetService('Players');

-- # Ranks
local Ranks = {
	[6] = {266723646}; -- # Owner;
	[5] = {}; -- # Super Admin;
	[4] = {}; -- # Admin;
	[3] = {}; -- # Moderator;
	[2] = {}; -- # VIP;
};

-- # Banned
local Banned = {};

-- # Prefix
local Prefix = ';';

-- # Functions
local GetRank = function(player: Player): number
	for rank, members in pairs(Ranks) do
		if table.find(members, player.UserId) ~= nil or table.find(members, player.Name) ~= nil then
			return rank;
		end;
	end;
	
	return 1;
end;

local CompareRank = function(rank1: number, rank2: number): {boolean} -- # {High Enough Rank: boolean, Same Rank: boolean}
	if rank1 == rank2 then
		return {true; true;};
	end;
	
	if rank1 > rank2 then
		return {true; false;};
	elseif rank1 < rank2 then
		return {false; false;};
	end;
	
	return {false; false};
end;

local CanRunCommand = function(command, requester: Player)
	local playerRank = GetRank(requester);
	
	if CompareRank(playerRank, command.MinRank)[1] == true then
		return true;
	end;
	
	return false;
end;

local CanRunOnPlayer = function(command, requester: Player, target: Player): boolean
	local MinRank = command.MinRank;
	
	local CanEvenRun = CanRunCommand(command, requester);
	
	if CanEvenRun == true then
		if command.SameRank == true then
			if CompareRank(GetRank(requester), GetRank(target))[1] == true then
				return true;
			end
			
			return false;
		elseif command.SameRank == false then
			if CompareRank(GetRank(requester), GetRank(target))[1] == true and CompareRank(GetRank(requester), GetRank(target))[1] == false then
				return true;
			end;
			
			return false;
		end
		
		return false;
	end
	
	return false;
end;

-- # Commands
local Commands = {};

function Commands.new(Name: string, NumberOfArgs: number, MinRank: number, SameRank: boolean, callBack: (caller: Player, targets: {Player}, ExcludedArgs: {string}) -> ())
	if Commands[Name:lower()] ~= nil then
		return;
	end;
	
	Commands[Name:lower()] = {
		Args = tonumber(NumberOfArgs) or 1;
		MinRank = tonumber(MinRank) or 7;
		SameRank = (typeof(SameRank) == 'boolean' and SameRank) or false;
		callBack = (typeof(callBack) == 'function' and callBack) or function()
			warn('Failed to run command, given callBack was not a function.');
		end;
	};
end;

-- # Actual Commands
local _Commands = require(script.Commands)

for i, v in pairs(_Commands) do
	Commands.new(i, unpack(v));
end;


-- # Player Functions
local FindTargets = function(caller: Player, strings: {string}): {Player?}
	local Found = {}
	
	for _, str in pairs(strings) do
		local low = str:lower();
		local len = string.len(str);
		
		if low == 'all' then
			for _, plr in pairs(Players:GetPlayers()) do
				if table.find(Found, plr) == nil then
					table.insert(Found, plr);
				end;
			end;
		elseif low == 'others' then
			local others = {};
			
			for _, plr in pairs(Players:GetPlayers()) do
				if plr ~= caller then
					if table.find(Found, plr) == nil then
						table.insert(Found, plr);
					end;
				end;
			end;
		elseif low == 'me' then
			if table.find(Found, caller) == nil then
				table.insert(Found, caller);
			end;
		else
			for _, v in pairs(Players:GetPlayers()) do
				local name = v.Name:lower();
				local display = v.DisplayName:lower();
				
				if string.sub(name, 1, len) == low or string.sub(display, 1, len) == low then
					table.insert(Found, v);
				end;
			end;
		end;
	end;
	
	return Found;
end;

local Chatted = function(player: Player, message: string)
	if string.sub(message, 1, 1) == Prefix then
		local msg = string.sub(message, 2);
		local Args = string.split(msg, ' ');
		local Command = Args[1];
		
		table.remove(Args, 1);
		
		if Commands[Command:lower()] then
			local AbleToRun = CanRunCommand(Commands[Command:lower()], player);
			
			if AbleToRun == true and #Args >= Commands[Command:lower()].Args then
				local Targets = {};
				local ExcludedArgs = {};
				
				if Commands[Command:lower()].Args == 1 then
					Targets = FindTargets(player, Args);
				elseif Commands[Command:lower()].Args > 1 then
					local newArgs = string.split(msg, ' ');
					table.remove(newArgs, 1);
					table.insert(ExcludedArgs, #newArgs);
					table.remove(newArgs, #newArgs);
					Targets = FindTargets(player, newArgs);
				end;
				
				for Index, target: Player in pairs(Targets) do
					if CanRunOnPlayer(Commands[Command:lower()], player, target) == false then
						if target ~= player then
							table.remove(Targets, Index);
						end;
					end;
				end;
				
				Commands[Command:lower()].callBack(player, Targets, ExcludedArgs);
			end;
		end;
	end;
end;

local PlayerAdded = function(player: Player)
	if table.find(Banned, player.UserId) ~= nil or table.find(Banned, player.Name) ~= nil then
		player:Kick('You are banned from this game.');
	end;
	
	player.Chatted:Connect(function(message: string)
		Chatted(player, message);
	end);
end;

-- # Connections
for _, v in ipairs(Players:GetPlayers()) do
	PlayerAdded(v);
end;

Players.PlayerAdded:Connect(PlayerAdded);

Commands Module:

--[[

COMMAND TEMPLATE:
['CommandName'] = {
		1; -- # Number Of Arguments Required
		2; -- # Minimum Rank To Run
		true; -- # Can Run On People With Same Rank.
		function(caller: Player, targets: {Player}, ExcludedArgs: {any}) -- # callBack function.
			
		end;
	};

]]--

return {
	['kill'] = {
		1;
		3;
		true;
		function(caller: Player, targets: {Player}, ExcludedArgs: {any})
			for _, target: Player in pairs(targets) do
				local Character = target.Character
				if not Character then
					continue;
				end;
				
				local Humanoid = Character:FindFirstChild('Humanoid');
				if not Humanoid then
					continue;
				end;
				
				Humanoid.Health = 0;
			end;
		end;
	};
	['night'] = {
		0;
		3;
		true;
		function(caller: Player, targets: {Player}, ExcludedArgs: {any})
			game:GetService('Lighting').ClockTime = 0;
		end;
	};
	['day'] = {
		0;
		3;
		true;
		function(caller: Player, targets: {Player}, ExcludedArgs: {any})
			game:GetService('Lighting').ClockTime = 12;
		end;
	};
	['to'] = {
		1;
		3;
		true;
		function(caller: Player, targets: {Player}, ExcludedArgs: {any})
			local Character = caller.Character;
			if not Character then
				return;
			end;
			
			for _, target: Player in pairs(targets) do
				local _Character = target.Character;
				if not _Character then
					continue;
				end;
				
				Character:PivotTo(_Character.PrimaryPart.CFrame);
			end;
		end;
	};
	['kick'] = {
		1;
		3;
		false;
		function(caller: Player, targets: {Player}, ExcludedArgs: {any})
			for _, target: Player in pairs(targets) do
				target:Kick(`You've been kicked by: {caller.Name}.`)
			end;
		end;
	};
};

Make sure you make the module inside of the script and name it “Commands”, otherwise if you don’t, don’t forget to change the _Commands variable to the path of the module.
image

Conclusion:


I hope this helps you with your basic moderation needs or helps you learn a little :smile:

3 Likes