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!
![]()
This is the main code
To explain it easily:
- It check the person who joined the game is admin or not.
- It checks every admin’s message in the chat to see if it contains a command.
- 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:
- /give
- me
- apple
- 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

