How To Make Admin Commands, A More In-Depth Guide: Part 4

After a long wait, part 4 is finally here. I haven’t been inspired to make a new tutorial, and to be honest, I forgot I even made this series. But after browsing the devforum, I found this. Anyways, enough about me. Welcome to part 4 of how to make your own admin commands.

If you haven’t already, read the first 3 parts, starting from part 1. This tutorial won’t help without it.
How To Make Admin Commands, A More In-Depth Guide: Part 3 - Resources / Community Tutorials - DevForum | Roblox

Setup


Now that that’s over with, it’s time to get started. This tutorial will be going over graphics, such as commands list, errors/info, etc. This is all client-sided, so we’ll make a new folder under the main MainModule called “Client.” Then, make LocalScript in the folder called “ClientMain”. Also, in the server “Main” ModuleScript, near the beginning of it (after the return function of course), add these 2 lines:

script.Parent.Parent.Client.Parent = game.StarterPack
script.Parent.Parent = game.ServerStorage

What they do is set up the Client folder in the StarterPack so the LocalScript can run, and move the Server folder away for storage because we don’t need it anymore.

Coding the UIs


In the following function, I put that in a seperate ModuleScript called “API”.

Now, let’s make another “API” ModuleScript in the “Modules” folder in the “Client” folder. Of course, you’re going to have to make your own GUIs. Now, let’s get coding.

function api:SendError(player, errormessage)
	local clientFolder = game.StarterPack:WaitForChild("Client")
	if not player.PlayerGui:FindFirstChild("ErrorUI") then
		local UI = clientFolder.GUIs.ErrorUI:Clone()
		local message = clientFolder.GUIs.ErrorMessage:Clone()
		UI.Parent = player.PlayerGui
		message.Text = errormessage
		message.Visible = true
		message.Parent = UI
	else
		local message = clientFolder.GUIs.ErrorMessage:Clone()
		local UI = player.PlayerGui:WaitForChild("ErrorUI")
		message.Text = errormessage
		message.Visible = true
		message.Parent = UI
	end
end

This is just an example for my admin system. You’ll need to write your own for your system. An example to use this would be, let’s say someone tries to ban their self, send an error to let them know they can’t do that.

Now, let’s make commands that are based on UI’s. Here, I’ll show you how to make a “chatlogs” command and a “cmds” command. Put this in the “Commands” ModuleScript in the “Modules” folder.

{
		name = "commands",
		info = "shows all the commands (this window :D)",
		aliases = {"cmds"},
		level = 0,

		execute = function(player, args)
			local clone = script.Parent.Parent.GUIs.CommandsUI:Clone()
			repeat clone.Parent = player.PlayerGui until clone.Parent == player.PlayerGui
		end,
	},
	{
		name = "chatlogs",
		info = "Shows everything everyone has said",
		aliases = {"logs", "clogs"},
		level = 1,

		execute = function(player, args)
			local clone = script.Parent.Parent.GUIs.LogsUI:Clone()
			clone.Parent = player.PlayerGui
		end,
	},

In the “Main” ModuleScript in the “Server” folder, add this after what we added at the beginning of the tutorial:

for _, command in pairs(require(script.Parent.Modules.Commands)) do
		local temp = game.StarterPack.Client.GUIs.Command:Clone()
		local info = Instance.new("StringValue", temp)
		info.Name = "commandInfo"
		info.Value = command["info"]
		temp.Parent = game.StarterPack.Client.GUIs.CommandsUI.Background.Container
		temp.Text = config["Prefix"]..command["name"]
		temp.Name = config["Prefix"]..command["name"]
	end
	for _, command in pairs(require(game.StarterPack.Client.Modules.Commands)) do
		local temp = game.StarterPack.Client.GUIs.Command:Clone()
		local info = Instance.new("StringValue", temp)
		info.Name = "commandInfo"
		info.Value = command["info"]
		temp.Parent = game.StarterPack.Client.GUIs.CommandsUI.Background.Container
		temp.Text = config["Prefix"]..command["name"]
		temp.Name = config["Prefix"]..command["name"]
	end

What this does is add each command from both the Client and Server into the commands UI. If you directly copy this, it won’t work because you need to make your own UI’s. These are just templates. Now, after the player chatted event add this.

require(game.StarterPack.Client.Modules.Logs).log(player, raw)

In the “Modules” folder in the “Client” folder, create a ModuleScript called “Logs”, then add this.

local logs = {}

function logs.log(player, msg)
	for _,v in pairs(game:GetDescendants()) do
		if v.Name == "LogsUI" then
			local temp = game.StarterPack.Client.GUIs.Template:Clone()
			temp.Text = "["..player.Name.."] "..msg
			temp.Parent = v.Background.Container
		end
	end
end

return logs

What this does is create a message in the Logs UI.

Ending


Thanks for reading my tutorial. This series is to give you a basic understanding of how to make modular admin commands. The code samples given here are just examples. You’ll need to make your own UIs and name them how you want. This will probably be the last part of the series, unless anyone asks for anything else. Please leave feedback, ideas, and suggestions below. Again, thanks for reading!


Read previous parts here:
Part 1
Part 2
Part 3


KeeAdmin: KeeAdmin // An Admin System to Fit All of Your Needs

4 Likes

Question, what is the point of ClientMain? I don’t see it being used anywhere in the tutorials.

Edit: Sorry for the bump.