Cmdr: A fully extensible and type safe command console for Roblox Developers

You’d define the group that can access the command on the client like in this image:

And then when you’ve done that, all you do is check the group the command is a part of in your hook check, and if the player has permission to run the command, you don’t return anything.

Here’s what I did for my hook check as an example:

I’ve had this setup for a while, and it hasn’t failed even once.

1 Like

The group parameter under CommandContext has the “any” type, but says it’s typically defined as a string:

The issue is that the ‘help’ command uses a table.sort method, which requires group to be defined as a string or an integer or else it will error.

I think this should be more clear in the documentation.

1 Like

Is it possible to change CommandContext.Group? If so, how would I do it?
Edit: I used my brain a realized I was doing permissions wrong, it’s literally just a string lol.

How to set this up? i can’t do it

What part are you struggling with? Have you read the tutorial in Cmdr’s website? I’ll summarize the basic setup from their site.

Server:

-- An example from Cmdr's website
-- This is a script you would create in ServerScriptService, for example.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Cmdr = require(path.to.Cmdr)

Cmdr:RegisterDefaultCommands() -- This loads the default set of commands that Cmdr comes with. (Optional)
-- Cmdr:RegisterCommandsIn(script.Parent.CmdrCommands) -- Register commands from your own folder. (Optional)
Cmdr:RegisterHooksIn(path.to.Hooks) -- Register the BeforeRun hook

Client:

-- An example from Cmdr's website
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Cmdr = require(ReplicatedStorage:WaitForChild("CmdrClient"))

-- Configurable, and you can choose multiple keys
Cmdr:SetActivationKeys({ Enum.KeyCode.F2 })

In another folder (in this example CmdrCommands), define the custom command and its behavior.
A ModuleScript named Teleport (or whatever else you want it to be):

-- An example from Cmdr's website
-- Teleport.lua, inside your commands folder as defined above.
return {
	Name = "teleport";
	Aliases = {"tp"};
	Description = "Teleports a player or set of players to one target.";
	Group = "Admin";
	Args = {
		{
			Type = "players";
			Name = "from";
			Description = "The players to teleport";
		},
		{
			Type = "player";
			Name = "to";
			Description = "The player to teleport to"
		}
	};
}

Another ModuleScript, this time named TeleportServer:

-- An example from Cmdr's website
-- TeleportServer.lua

-- These arguments are guaranteed to exist and be correctly typed.
return function (context, fromPlayers, toPlayer)
  if toPlayer.Character and toPlayer:FindFirstChild("HumanoidRootPart") then
    local position = toPlayer.Character.HumanoidRootPart.CFrame

    for _, player in ipairs(fromPlayers) do
      if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
        player.Character.HumanoidRootPart.CFrame = position
      end
    end

    return "Teleported players."
  end

  return "Target player has no character."
end

You will also need to setup a BeforeRun hook, otherwise Cmdr will not run. I will put this inside a folder called Hooks in this example, but you can call it whatever you want

-- An example from Cmdr's website
-- A ModuleScript inside your hooks folder.
return function (registry)
	registry:RegisterHook("BeforeRun", function(context)
		if context.Group == "DefaultAdmin" and context.Executor.UserId ~= game.CreatorId then
			return "You don't have permission to run this command"
		end
	end)
end

And finally, in the same server script where we registered Cmdr’s default commands, register the custom commands and hooks. Here’s how you would do it:

Cmdr:RegisterCommandsIn(script.Parent.CmdrCommands) -- Register commands from your own folder. (Optional)
Cmdr:RegisterHooksIn(path.to.Hooks) -- Register the BeforeRun hook

I wrote this up in like 10 minutes so it might be a bit sloppy but hope this helps!

1 Like