How would I make a commandbar command in my plugin?
I’ve seen plugins do it, but I’m not sure how I would detect whenever the user pressed the enter key to execute the command.
How would I make a commandbar command in my plugin?
I’ve seen plugins do it, but I’m not sure how I would detect whenever the user pressed the enter key to execute the command.
You would use something like on a textbox function like Textbox.FocusLost which in the first parameter it checks if the user pressed enter with a boolean value, heres an example from the roblox documents:
https://create.roblox.com/docs/reference/engine/classes/TextBox#Focused
How would I access the command bar as a textbox?
Do you mean like the list of commands or accessing the commandbar when pressing a key?
I mean like registering whenever someone presses enter in the commandbar so I can check the text in the command bar and make a command - As an example “config ”, so like custom commands like that.
For texts with commandbar, you just do textbox.Text, as it gets the text before it gets erased by the textbox when it gets focused on again.
Example:
local textbox = script.Parent
textbox.FocusLost:Connect(function(wasEnterPressed)
if wasEnterPressed then
print(textbox.Text) --Example, would print what u would type inside the textbox.
end
end)
And then to put on that, you put the own code when the string matches the opposed command, and a couple of checks for players that are non-admin.
I know that textboxes have a FocusLost signal, but I don’t know how I would access the command bar as a textbox. I obviously can’t put a script inside of the commandbar, so I can’t do script.Parent.
Like for example, pressing a key makes the command bar appear like with HD Admin when you press ~ or Ç?
I’m talking about the Roblox studio command bar, not a custom GUI.
Oh i get it now, you are trying to make a script run when the player types a command on it right?
Correct.
For example like, using the textbox as a code to execute like in roblox’s studio command bar, so it executes code?
Okay so, I am making a plugin, and I want users to be able to interact with said plugin via the command bar.
So let me break this down, you want people to interact with your plugin if they type a specific command, so they can interact with it right?, If thats the case then ill try to replicate that in studio to give out the code.
Yes.
I dont know if this is reliable, but this is how i think you can do it:
local Commands = {
[1] = {
"helloprint"
}
}
script.Parent.FocusLost:Connect(function(hasEntered)
if hasEntered then
for i , v in ipairs(Commands) do
if script.Parent.Text == v[1] then
if v[1] == "helloprint" then
print("Hello World!")
end
end
end
end
end)
I don’t think there is a way that quite does/allows this.
To my knowledge, you cannot define new commands and you cannot access the command bar’s environment.
There is a way to achieve something similar to this though. It is possible to read the output of the command bar via LogService.
So doing
game.LogService.MessageOut:Connect(function(m, t)
if t ~= Enum.MessageType.MessageOutput then return end
if m == "> testcommand" then
print("pong!"))
end
end)
would allow you to achieve
![]()
Please note the "> " prefix before our command’s name. That has to be there, as it appears in the log when you type a command.
You could also define your commands in the _G table.
as long as you are using this for a plugin, and not in game, then i believe something like this should work:
local Source = "local p = Instance.new('Part') p.Parent = workspace print(`hi, {p}`)"; local tempModule = Instance.new('ModuleScript'); tempModule.Source = `{Source}\nreturn nil`; require(tempModule); tempModule:Destroy();
saw this method on another post like a year ago, i have never made a plugin so i dont know if this will actually work or not, i tested this on the studio command bar itself
As I said, I am making a plugin, not runtime code. ![]()