How do I check when a player is selecting an explorer object with a plugin?

Hello again! I’ve just been helped with creating gui mechanics with a plugin and I need one last thing. How would I check if an object in the explorer is being selected? Here is the post to my previous question.

My plugin needs to check what object is being selected from the explorer to change the source code inside of it if its a script.

You can use game.Selection.Selection.SelectionChanged to respond to changes in the selection

You can use Selection:Get() to get a table of the current selected instances in studio. You can use Selection:Set(t) to set the selection to the instances in the table.

You can listen for Selection.SelectionChanged to detect when the selection changes.

3 Likes

Thanks I got it down pretty quickly. By chance do you know if I can for loop through the selections? because I’ve noticed that if I select 2 things it only prints the 2nd selection.

InstructionsLabel.MouseButton1Click:Connect(function()
	print(game.Selection:Get()[#game.Selection:Get()])
end)

Thats my script.

Yes. Selection:Get() returns a table

for _, selected in ipairs(game.Selection:Get()) do
    print(selected)
end
1 Like