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

Get

Returns an array of currently selected Instances in Roblox Studio.

If no Instances are selected, the array returned 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.

Returns

Return Type Summary

An array of currently selected Instances.


Code Samples


Selection.SelectionChanged

This example prints the number of selected items whenever SelectionChanged is fired:

local selection = game:GetService("Selection")
selection.SelectionChanged:Connect(function()
	print("Selection contains " .. #selection:Get() .. " items.")
end)

Selection

The following code sample, when used in a plugin or the command bar, will rotate currently selected BaseParts.

local Selection = game:GetService("Selection")

for _, object in pairs(Selection:Get()) do
	if object:IsA("BasePart") then
		object.CFrame = object.CFrame * CFrame.Angles(0, math.pi / 2, 0)
	end
end