Selection Service not detecting selected GUI objects

The selection service (game:GetService(“Selection”)) does not detect any GUI objects.

In the selection service, there is a method where you do SelectionService:Get() which returns a table of everything selected. This works mostly, but it does not detect GUI objects. I have no idea why, if its a bug, or if my studio is broken. Either way, it’s a problem.

I’ve tried moving the GUI objects into workspace, and other things in explorer, as well as surface gui, yet no matter what, they still weren’t in the table.

image
Works fine for me

Perhaps it was a studio bug. I will go test it again in different studio sessions and see if it works.

It works when I click the plugin button, but when I click the gui buttons that open when i click the plugin button, it doesnt work. Not sure why.

This only happens with gui objects. ScreenGui is fine, but anything that would go inside doesnt work.

Please provide your code if you have any, otherwise, this issue isn’t related to #help-and-feedback:scripting-support. Simply describing your problem isn’t enough if the problem may be code-related.

Add any supporting/related information, such as output errors concerning your code, and/or which lines you think (or the output thinks) are causing the issue.

1 Like

This is my test script, basically the same as my normal script except removes the stuff that’d be inside of the if statement.

local S = game:GetService("Selection")

local toolbar = plugin:CreateToolbar("Name")
local button = toolbar:CreateButton("Name", "Description","rbxassetid://1234567890")

local gui = script:WaitForChild("mainGui",10)

local guiObjectNames = {"TextLabel","Frame","TextButton","ImageButton","Image","TextBox"}

button.Click:Connect(function()
	for i,v in pairs(S:Get()) do
		print(v) -- This DOES print GUI objects.
	end
	
	if gui.Parent == script then
		gui.Parent = game:WaitForChild("CoreGui")
	elseif gui.Parent == game:WaitForChild("CoreGui") then
		gui.Parent = script
	end
end)

for _,button in pairs(gui:WaitForChild("Background"):GetChildren()) do
	if button:IsA("TextButton") then
		button.MouseButton1Click:Connect(function()
			print("A") -- prints "A"
			for i,inst in pairs(S:Get()) do
				print(inst.Name)
				print(type(inst)) -- Does not print GUI objects
				
				if table.find(guiObjectNames,type(inst)) then
					print("It is of the granted gui objects.")
					--do stuff here
				end
			end
		end)
	end
end

Basically the S:Get() table does not include GUI objects when it’s pressed by the GUI button

If you see the selected items on the Explorer getting unhighlighted when you click on the CoreGui interface, then it will not print the items. Try opting for widgets instead.

According to my tests, I have no problems printing selected UI items, until my selection disappears from the Explorer.

I’m not sure what you’re doing where you have no problem printing the selected UI objects, because for me it specifically doesn’t work for the UI objects. Everything else prints fine.

How is your UI set up? Any video of what is happening on your end with the issue (the explorer should be in the frame)?

The GUI for the plugin is just a frame with some text buttons. The GUI I’m testing it on is just a frame (also tested it on textlabel, and textbutton) in a ScreenGui, which is in StarterGui (which is obviously in the explorer).

I see now. You should just use widgets, as I have said. This is intentional behavior as a result of the UI Editor, overriding the selection behavior.

1 Like