PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

CreatePluginAction

This function creates a PluginAction which is an object that represents a generic performable action in Roblox Studio, with no directly associated Toolbar or Button. In Roblox Studio, they can be assigned a keyboard shortcut under File → Advanced → Customize Shortcuts…, and they can also be added to the Quick Access Toolbar.

When an action is triggered, the PluginAction/Triggered event is signaled.

In order for PluginActions work as expected, they must be created using this function.

See also

  • articles/Intro to Plugins, an introductory article to plugin use and development
  • PluginMenu, a context menu that can be shown in Studio which displays a list of PluginActions and supports submenus
  • Plugin/CreatePluginMenu, creates a PluginMenu

Parameters

Name Type Default Description

Must be a unique string that identifies this PluginAction from others

The displayed name of the action

The displayed description of the action

The name of the icon used to display the plugin

true

Whether the PluginAction will be hidden from Studio’s shortcuts view. Useful for contextual actions. Defaults to true

Returns

Return Type Summary

The newly created PluginAction object


Code Samples


Creating a PluginAction and PluginMenu

This code sample visualizes how PluginMenu|PluginMenus and PluginAction|PluginActions behave when created for a Plugin. Outside of this example, you should not parent the plugin or its functional components to the game’s workspace.

In order to work as expected, the code block must but pasted into the command bar, but only once. Consecutive attempts at executing the code in the command bar will result in an error because a plugin cannot create more than one PluginMenu with the same id.

After executing the code, changing the created BoolValue in the game’s workspace via the Explorer window opens the plugin’s menus. Selecting an action from the menus the function connected to the trigger signal.

Example Plugin in Studio Explorer Window

-- This code can be pasted into the command bar, but only once.

local plugin = plugin or getfenv().PluginManager():CreatePlugin()
plugin.Name = "Plugin"
plugin.Parent = workspace

local pluginMenu = plugin:CreatePluginMenu(math.random(), "Test Menu")
pluginMenu.Name = "Test Menu"

pluginMenu:AddNewAction("ActionA", "A", "rbxasset://textures/loading/robloxTiltRed.png")
pluginMenu:AddNewAction("ActionB", "B", "rbxasset://textures/loading/robloxTilt.png")

local subMenu = plugin:CreatePluginMenu(math.random(), "C", "rbxasset://textures/explosion.png")
subMenu.Name = "Sub Menu"

subMenu:AddNewAction("ActionD", "D", "rbxasset://textures/whiteCircle.png")
subMenu:AddNewAction("ActionE", "E", "rbxasset://textures/icon_ROBUX.png")

pluginMenu:AddMenu(subMenu)
pluginMenu:AddSeparator()

pluginMenu:AddNewAction("ActionF", "F", "rbxasset://textures/sparkle.png")

local toggle = Instance.new("BoolValue")
toggle.Name = "TogglePluginMenu"
toggle.Parent = workspace

local function onToggled()
	if toggle.Value then
		toggle.Value = false
		
		local selectedAction = pluginMenu:ShowAsync()
		if selectedAction then
			print("Selected Action:", selectedAction.Text, "with ActionId:", selectedAction.ActionId)
		else
			print("User did not select an action!")
		end
	end
end

toggle.Changed:Connect(onToggled)