Super easy command system!

Hello! I made a super compact and easy encapsulated command script.
I hope you guys enjoy!
If you have any question or something, feel free to ask!

image

This is the main code
To explain it easily:

  1. It check the person who joined the game is admin or not.
  2. It checks every admin’s message in the chat to see if it contains a command.
  3. When it finds a command from an admin, it splits the message into 3 parts.
Example

If the admins says [/give me apple] then it split into:

  1. /give
  2. me
  3. apple
  1. pass to the commands module script.

And config

whole codes for copy
--main script
local SStorage = game:GetService("ServerStorage")

local PlayerEventHub = require(SStorage.genreral.PlayerEventHub)
local config = require(script.commandsConfig)
local admins = config.admins
local commands = config.commands

PlayerEventHub.OnPlayerAdded(function(plr)
	
	if admins[plr.UserId] then
		plr.Chatted:Connect(function(msg)
			local strings = msg:split(" ")
			local command = strings[1]
			
			if commands[command] then
				
				local target = strings[2]
				local detail = strings[3]
				
				if target == "me" then
					target = plr
				else
					target = game.Players:FindFirstChild(target)
					if target == nil then
						warn(target.. " is not existing")
						return
					end
				end
				
				commands[command](plr, target, detail)
			end
		end)
	end
end)
--config
local SStorage = game:GetService("ServerStorage")

local DataStoreModule = require(SStorage.DataStore)

local module = {
    
    admins = {
        [2876212538] = {rank = 1}, --your user ID and rank here! (rank isn't needed)
        [38811] ={rank = 1}, --Bread
    },
    
    commands = {
        ["/CommandName"] = function(plr, toWhom, detail) --this command is an example
           --write the code what you want to do!
        end
    },
    
    
}

return module

obviously needs to support arguments other than the player who used the command, for example you can’t make a /give plr item command with this

1 Like

You’re right. I was actually thinking about extending it to solve that problem.
I’ll update the code. Thank you!