I am making a plugin that needs a part to be selected. How would I check which part is selected in Studio for this plugin?
Not the games player I mean in studio, as you’ve seen in many others like building plugins, they can detect how to get the part you’ve selected, does anyone know how to do this?
blokav
(blokav)
January 30, 2021, 1:22am
#2
game.Selection:Get()
returns an array of all instances that are currently selected in studio.
1 Like
blokav
(blokav)
January 30, 2021, 1:23am
#3
Additionally, you can force the user to select a group of objects by passing an array into game.Selection:Set()
https://developer.roblox.com/en-us/api-reference/class/Selection
So now I have this,
local toolbar =
plugin:CreateToolbar("TheBaconHero_101's Plugins")
local newScriptButton = toolbar:CreateButton("Create AttachmemtPoint for scope", "Creates AttachmemtPoint for scope", "")
newScriptButton.Click:Connect(function()
local Selected = game.Selection:Get()
print(Selected)
local attachPoint = Instance.new("Attachment")
attachPoint.Parent = Selected
end)
Its printing the part that its getting, but not setting the parent, is there something else I’m supposed to do?
blokav
(blokav)
January 30, 2021, 1:40am
#5
“Selected” is going to be an array, so to get the actual part you’d have to index it.
newScriptButton.Click:Connect(function()
local Selected = game.Selection:Get()[1]
print(Selected)
local attachPoint = Instance.new("Attachment")
attachPoint.Parent = Selected
end)
2 Likes