Command API
Everything a command can safely reference lives in CommandAPI:
local CommandAPI = require(script:FindFirstAncestor("HD Admin").Core.CommandAPI)
Loading¶
loadCommands Server¶
CommandAPI.loadCommands(details): Commands
This is what the pack modules under Config > Commands use to load, tag and modify their command sets. Open any of the packs there to see it in action.
Prompts¶
prompt Shared¶
-- In a server command module
CommandAPI.prompt(promptType: PromptType, player: Player, text: string, options: PromptOptions?): PromptHandle
-- In a client command module
CommandAPI.prompt(promptType: PromptType, text: string, options: PromptOptions?): PromptHandle
Shows a notice, message or card. For action prompts with buttons, see bindPrompt.
| Prompt type | What it shows |
|---|---|
"info" "success" "warn" "error" |
A sidebar notice in the matching style with a sound effect |
"message" |
A centre-screen message, like ;message |
"hint" |
A bar across the top of the screen, like ;hint |
"privateMessage" |
A sticky sidebar notice which opens the full message, with a reply box, when clicked |
"alert" |
A sticky sidebar notice that loops a sound until muted, and opens the full message when clicked |
"action" |
A card with buttons and controls. Create these with task:bindPrompt, which covers the buttons, sliders and config in full |
CommandAPI.prompt("success", task.caller, "Quest complete!", {duration = 5})
It returns a connection that you can disconnect connection:Disconnect() to end the prompt. You can add these for example to a task's janitor to end it as soon as the command ends:
task.janitor:add(CommandAPI.prompt("hint", task.target, "You're frozen until an admin releases you", {duration = 0})) -- 0 means "infinite"
Options
All of these are optional and work on every prompt type unless the row says otherwise:
| Option | Type | What it does |
|---|---|---|
title |
string | The heading above the text. privateMessage and alert set their own |
duration |
number | Seconds before the prompt dismisses itself. Leave it out and one is worked out from the text length. 0 keeps it on screen until it's dismissed or disconnected |
subtext |
string | A smaller line under the text |
icon |
string | An rbxassetid:// image which replaces the notice's icon |
color |
Color3 | Tints the text of a hint |
dismissable |
boolean | false hides the close button, so only duration or the handle can remove it |
openPage |
string | Clicking the notice opens the panel on this page, like "Commands", "Roles", "Settings" or "About" |
openProfile |
boolean | Clicking the notice opens the player's own profile |
openImage |
table | {image = "rbxassetid://...", title = "Map", ratio = 16/9}. Clicking the notice opens the image centre-screen |
linkButtons |
table | Small buttons along the foot of the notice. {label = "Roles", page = "Roles"} opens a page and {label = "Profile", profile = true} opens their profile. Add style = "Neutral" for a muted button |
roleBadges |
table | Role pills under the title, {{name = "Admin", color = Color3.fromRGB(255, 170, 0)}} |
countdown |
number | Counts down live from this many seconds wherever %TIME% appears in the text |
fromUserId |
number | Shows that user's avatar, name and top role as the sender of a message, privateMessage or alert |
CommandAPI.prompt("info", task.caller, "You've unlocked the VIP role", {
title = "New role",
openPage = "Roles",
roleBadges = {{name = "VIP", color = Color3.fromRGB(255, 170, 0)}},
})
For action prompts with buttons, see bindPrompt.
Character¶
getHumanoid Shared¶
CommandAPI.getHumanoid(player: Player?): Humanoid?
The player's Humanoid, or nil if their character isn't present.
getHRP Shared¶
CommandAPI.getHRP(player: Player?): BasePart?
The player's HumanoidRootPart, or nil.
getHead Shared¶
CommandAPI.getHead(player: Player?): (BasePart?, Model?)
The player's Head and their character, or nil.
getNeck Shared¶
CommandAPI.getNeck(player: Player?): Motor6D?
The player's neck joint, or nil. Works for both R6 and R15 rigs.
getTorso Shared¶
CommandAPI.getTorso(player: Player?): Instance?
The player's torso, or nil. Works for both R6 and R15 rigs.
loadCharacter Server¶
CommandAPI.loadCharacter(player: Player?)
Respawns the player's character. Always use this over player:LoadCharacter() so HD Admin's tasks know the respawn was intentional.
Players¶
getUserInfoAsync Shared¶
CommandAPI.getUserInfoAsync(userId: number | string): (boolean, UserInfo | string)
Returns true and the UserInfo for any user, even offline ones, or false and a reason. Results are cached, so repeat calls are free.
getNameFromUserIdAsync Shared¶
CommandAPI.getNameFromUserIdAsync(userId: number | string): (boolean, string)
Returns true and the user's name, or false and a reason. Works for offline users.
teleportAsync Server¶
CommandAPI.teleportAsync(player: Player?, cframe: CFrame): (boolean, string)
Moves the player's character to the given CFrame, unseating them first so they don't drag their seat along.
unequipTools Server¶
CommandAPI.unequipTools(player: Player?): (boolean, string)
Moves the player's equipped tool back into their backpack.
Tasks¶
getTasks Shared¶
CommandAPI.getTasks(commandKey: string?, targetUserId: number?): {Task}
Returns the running tasks, optionally filtered by command and target. These are the same task objects the Task API describes.
getTasksByCallerId Shared¶
CommandAPI.getTasksByCallerId(callerUserId: number): {Task}
Every running task started by the given caller.
Chat¶
systemMessage Shared¶
-- In a server command module
CommandAPI.systemMessage(player: Player, text: string)
-- In a client command module
CommandAPI.systemMessage(text: string)
Sends a system-styled message into the player's chat.
forceChat Shared¶
-- In a server command module
CommandAPI.forceChat(player: Player, text: string)
-- In a client command module
CommandAPI.forceChat(text: string)
Makes the player say the given message.
forceBubbleChat Shared¶
CommandAPI.forceBubbleChat(target: Player | Model, text: string)
Shows a chat bubble above the player's character, or above any model or part you pass instead.
Outfits¶
getDescription Server¶
CommandAPI.getDescription(humanoid: Humanoid): HumanoidDescription
The humanoid's current HumanoidDescription.
applyDescription Server¶
CommandAPI.applyDescription(humanoid: Humanoid?, description: HumanoidDescription?, properties: {[string]: any}?): HumanoidDescription?
Applies the HumanoidDescription safely, retrying when Roblox rejects the first attempt. Pass properties to tweak fields on top of the base description.
outfitBuff Server¶
CommandAPI.outfitBuff(target: Player, properties: {[string]: any})
Applies HumanoidDescription properties as a buff which undoes itself when the task ends, so commands like ;wormify clean up on their own.
setFakeBodyParts Server¶
CommandAPI.setFakeBodyParts(character: Model, info: {[string]: any}): (() -> ())?
Swaps body parts for command-made stand-ins and returns a function that restores the originals.
clearFakeBodyParts Server¶
CommandAPI.clearFakeBodyParts(character: Model)
Removes those stand-ins again.
runBundleId Server¶
CommandAPI.runBundleId(task: Task, bundleId: number, properties: {[string]: any}?)
Dresses the task's target in a catalog bundle, restoring their own outfit when the task ends.
Assets¶
registerSound Shared¶
CommandAPI.registerSound(sound: Sound)
Required for any Sound your command creates, so the game's volume and pitch settings apply to it.
setAnchored Shared¶
CommandAPI.setAnchored(instance: Instance, anchored: boolean)
Anchors or unanchors every part under the instance.
setTransparency Shared¶
CommandAPI.setTransparency(instance: Instance, transparency: number)
Fades every part under the instance.
promptPurchaseAsync Server¶
CommandAPI.promptPurchaseAsync(assetId: number, player: Player?, infoType: Enum.InfoType?)
Prompts the player to purchase the asset, routing to the right purchase flow for its type.
ownsAssetAsync Server¶
CommandAPI.ownsAssetAsync(assetId: number, player: Player?): boolean
Whether the player owns the asset.
isTypeAsync Server¶
CommandAPI.isTypeAsync(assetId: number, assetType: Enum.AssetType | Enum.BundleType): (boolean, string?)
Verifies the asset is of the given type. Returns true, or false and the reason.
loadAssetCommand Server¶
CommandAPI.loadAssetCommand(assetType: Enum.AssetType, task: Task, assetId: number, callback: (item: Instance) -> ())
Verifies the asset is of the given type and permitted, inserts it, then hands it to your callback to place. This powers ;gear.
getToolsInfoAsync Server¶
CommandAPI.getToolsInfoAsync(): (boolean, {ToolInfo} | string)
Returns true and the ToolInfo of every tool available to ;give, or false and a reason.
Utility¶
getTargets Server¶
CommandAPI.getTargets(targetType: "All" | "Others" | "Nearby" | "OthersNearby", originPlayer: Player?, radius: number?): {Player}
Resolves a qualifier into the players it covers right now. "Nearby" and "OthersNearby" measure from the origin player, using radius studs (50 by default).
setCameraSubject Client¶
CommandAPI.setCameraSubject(newSubject: Instance)
Points the local player's camera at a new subject, like another player's Humanoid for ;view.
runPromptCommand Server¶
CommandAPI.runPromptCommand(promptType: PromptType, task: Task, targets: {Player}, text: string, options: PromptOptions?)
The engine behind ;message, ;hint and similar prompts. It filters the text, shows the prompt to every target, and keeps the task alive until the prompt expires.
runEmoteId Server¶
CommandAPI.runEmoteId(task: Task, emoteId: number, speed: number?, looped: boolean?)
Plays the emote animation on the task's target, ending it when the task ends.
createEmoteCommand Server¶
CommandAPI.createEmoteCommand(emoteName: string, emoteId: number, properties: {[string]: any}?): Command
Returns a complete emote command, ready to drop into your commands array. properties overrides any field on the generated command.
createBundleCommand Server¶
CommandAPI.createBundleCommand(commandName: string, bundleId: number, properties: {[string]: any}?): Command
The same behaviour for bundle commands like ;ratdance.
bindEmotePrompt Server¶
CommandAPI.bindEmotePrompt(task: Task, target: Player, emoteId: number, emoteName: string?, isLooped: boolean?)
Binds the emote action card to the task, so the target can favourite the emote or view it in the catalog.
openProfile Server¶
CommandAPI.openProfile(player: Player?, userId: number)
Opens the given user's profile popup for the player.
openPage Server¶
CommandAPI.openPage(player: Player?, pageId: string, tabLabel: string?)
Opens the player's panel straight onto the given page, optionally onto one of its tabs.
openEmotes Server¶
CommandAPI.openEmotes(player: Player?)
Opens the emotes popup for the player.
colourRoleName Shared¶
CommandAPI.colourRoleName(role): string
The role's name wrapped in its colour, for rich text.
isTableEmpty Shared¶
CommandAPI.isTableEmpty(tbl: {[any]: any}): boolean
Whether the table has no entries at all, including keyed ones #tbl misses.
round Shared¶
CommandAPI.round(number: number, decimalPlaces: number?): number
Rounds a number to the given decimal places, or to a whole number by default.
Types¶
Commands¶
type Commands = {Command}
The array a command module returns.
Command¶
One command table within Commands (name, args, run, and so on). Custom Commands covers every field.
Task¶
The task object passed into every run function, covered in full by the Task API.
ClientCommands¶
The client-half equivalent of Commands, returned by the Client module.
ClientCommand¶
One client-half command table within ClientCommands.
UserInfo¶
type UserInfo = {
userId: number | string,
userName: string,
userImage: string,
userDisplayName: string,
userTopRole: {key: string, name: string, color: Color3}?,
}
userTopRole is only present for players in this server.
ToolInfo¶
type ToolInfo = {
name: string,
textureId: string,
tool: Tool?,
}
PromptType¶
type PromptType = "info" | "success" | "warn" | "error" | "message" | "hint" | "privateMessage" | "alert" | "vote" | "voteResults" | "action"
The prompt type strings. See prompt for what each one shows.
PromptOptions¶
The options table prompt accepts, listed in full under prompt.
PromptHandle¶
The handle prompt returns, which dismisses the prompt early with handle:Disconnect().