Skip to content

Service · inherits Instance

Selection

Official docs ↗

The Selection service controls the Instances that are selected in Roblox Studio.

About Selection

The Selection service controls the Instances that are selected in Roblox Studio.

This service is particularly useful when developing Plugins, as it allows the developer to access and manipulate the current selection.

Currently selected Instances can be obtained and set using the Selection.Get and Selection.Set functions. The Selection.SelectionChanged event fires whenever the current selection changes.

For more information on using Selection and Plugins, see Plugin.

Selection is also often used in the command bar, to set hidden properties or run functions for selected Instances.

Note this class only applies to Roblox Studio and has no applicability to games.

Properties 1

  • SelectionThickness: floatReadOnlyNotReplicatedThe thickness of the selection highlight outline drawn around selected Instances in Roblox Studio's viewport.

    The thickness of the selection highlight outline drawn around selected Instances in Roblox Studio's viewport.

    This read-only property returns the current outline thickness as a float. The default value is 0.02. The value is controlled by Roblox Studio and cannot be changed through the scripting API.

    This property can be read in Plugins to query the current selection visualization setting, such as when drawing custom overlays that need to match the built-in selection appearance.

Methods 4

  • Add(instancesToAdd: Instances) → ()PluginAdds the given Instances to the current selection in Roblox Studio.

    Adds the Instances in the given array to the current selection. Instances that are already selected remain selected.

    Calling this function fires the Selection.SelectionChanged event if any new Instances are added to the selection.

    Note this function can only be used in Plugins or the command bar. For setting the selection to an entirely new set of instances, see Selection.Set. For removing instances from the current selection, see Selection.Remove.

  • Get() → InstancesPluginReturns an array of currently selected Instances in Roblox Studio.

    Returns an array of currently selected Instances in Roblox Studio.

    If no Instances are selected, the array returned will be empty. This function can be used in conjunction with the Selection.SelectionChanged event to get the selection whenever it changes.

    Note, this function can only be used in Plugins or the command line.

    For changing the current selection, please see Selection.Set.

  • Remove(instancesToRemove: Instances) → ()PluginRemoves the given Instances from the current selection in Roblox Studio.

    Removes the Instances in the given array from the current selection. Instances that are not currently selected are ignored.

    Calling this function fires the Selection.SelectionChanged event if any Instances are removed from the selection.

    Note this function can only be used in Plugins or the command bar. For adding instances to the current selection, see Selection.Add. For replacing the selection entirely, see Selection.Set.

  • Set(selection: Instances) → ()PluginSets the currently selected objects in Roblox Studio to Instances in the given array.

    Sets the currently selected objects in Roblox Studio to Instances in the given array.

    Calling this function will cause the Selection.SelectionChanged event to fire, unless the new selection set is identical to the previous selection.

    Note this function overwrites the existing selection. However, using Selection.Get an Instance can be added to the existing selection like so:

Events 1

  • SelectionChangedSelection.SelectionChanged:Connect(function())Fires when the Instances selected in Roblox Studio changes.

    Fires when the Instances selected in Roblox Studio changes.

    Note this event does not give the new selection. Developers will need to use the Selection.Get function to obtain the current selection.

    Although this event can be used outside of plugins and the command bar, it only applies to the selection in Roblox Studio and therefore has no functionality outside of Studio.

    To change the selection use the Selection.Set function.

Selection also has every member of Instance. Deprecated and Roblox-only members are hidden.

Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.