PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

Enabled

PluginToolbarButton

bool

Enabled determines whether a button is clickable in general. When this property is false, the button will be greyed out and unclickable, preventing the user from firing the PluginToolbarButton/Click|Click event. Buttons are enabled by default.

Plugins should disable their buttons when the button action isn’t relevant in the current context. For example, a plugin button that assigns random colors to selected should not be enabled when the selection contains no parts. See the code samples for more information.

See also

  • PluginToolbarButton/ClickableWhenViewportHidden|ClickableWhenViewportHidden, which determines whether a button is clickable when the game view is hidden (and not just in general)


Code Samples


BrickColor Randomizer Plugin

This code sample is for a studio Plugin. The plugin creates a PluginToolbarButton which randomizes the BasePart/BrickColor|BrickColor of each selected part using BrickColor.random(). Furthermore, the button is only enabled if at least one part is selected. It does this by detecting changes in the Selection using Selection/SelectionChanged|SelectionChanged.

assert(plugin, "This script must be run as a plugin")

local Selection = game:GetService("Selection")

local toolbar = plugin:CreateToolbar("Parts")
local pluginToolbarButton = toolbar:CreateButton(
	"Randomize Colors",
	"Click this button to assign random colors to selected parts",
	"rbxassetid://5325741572" -- A rainbow
)

-- Color randomizer button
local function onClick()
	local sel = Selection:Get()
	for _, object in pairs(sel) do
		if object:IsA("BasePart") then
			object.BrickColor = BrickColor.random()
		end
	end
end
pluginToolbarButton.Click:Connect(onClick)

local function doesSelectionContainAPart()
	local sel = Selection:Get()
	for _, object in pairs(sel) do
		if object:IsA("BasePart") then
			return true
		end
	end
	return false
end

-- Detect changes in the selection
local function onSelectionChanged()
	pluginToolbarButton.Enabled = doesSelectionContainAPart()
end
Selection.SelectionChanged:Connect(onSelectionChanged)
onSelectionChanged()