How to make your plugin change colors depending on the UI you click

I’m trying to make a plugin, and I’m just doing some testing to figure out how this all works…But I want to make a Frame’s BackgroundColor3 change to the color of the UI item I’m clicking in studio (either in the explorer or camera view)

I’ve search on the wiki to try and find references…But I haven’t been able to find any information on how to do so.

Let me know if any one knows how to achieve this, or if you have questions.

2 Likes

That’s actually kind of a complex goal, so if possible I suggest you try doing something simpler, but if you really want to do it:

There’s no actual built-in way to get the element the mouse is hovering over, so we have to do that manually using math, the mouse position and every element’s AbsolutePosition and AbsoluteSize. Essentially, checking whether the mouse position is within the box created by the two points AbsolutePosition and AbsolutePosition + AbsoluteSize.

In addition to this, you’ll need to make essentially a custom ZIndex detection system to get which element (when there are two or more on top of each other) should have it’s color taken. It’d be great if we had screen color detection functionality, but we don’t so we need to do it manually.

Actually retrieving the color from the element is the easy part, getting the element is the hard part.

1 Like

Alright, thanks for explaining this to me!
Maybe is it possible to get the selection in the Explorer and get the Color3 from that?

It sounds easy in my head but since I’ve never done this I honestly have no clue.

1 Like

Yeah that is much easier :wink:

I found this documentation on robloxdev, But I’m not sure if this is what I need to use?

Note: I switched it to just printing object.Name instead of moving the object.

I tried it but can’t get it to work. Do you know if this is what I should be using or could you point me in the right direction?

Thanks

Yep, that should work.

When are you printing? Every time the user clicks?

1 Like

Sorry forgot to update. This is more of like a PICNIC error. Problem In Chair Not In Computer. haha
(I forgot to update the plugin)

I’ve got it to print the name now! :smiley:

1 Like

Oop never mind. I still need help.

So I did some research and found some stuff on the wiki. I’m creating a dockable plugin, but somehow I got it to open and close once and print the name, but I can’t get it to open and close anymore.

Code
local toolbar = plugin:CreateToolbar("Test Plugin")
local newScriptButton = toolbar:CreateButton("Add Script", "Create an empty Script", "rbxassetid://1507949215")

local info = DockWidgetPluginGuiInfo.new(
	Enum.InitialDockState.Float, -- Window will be initialized in a floating state.
	true,                        -- Window will be initially enabled.
	false,                       -- Don't override the saved enabled/dock state.
	200,                         -- Width of the floating window.
	100                          -- Height of the floating window.
)
 
local pluginGui = plugin:CreateDockWidgetPluginGui("Hello_world_widget", info)
 
local testBtn = Instance.new("TextButton")
testBtn.TextScaled = true
testBtn.AnchorPoint = Vector2.new(0.5,0.5)
testBtn.Size = UDim2.new(1,0,1,0)
testBtn.Position = UDim2.new(0.5,0,0.5,0)
testBtn.SizeConstraint = Enum.SizeConstraint.RelativeYY
testBtn.BackgroundColor3 = Color3.new(1,0.5,0)
testBtn.Text = "Hello world!"
testBtn.Parent = pluginGui

testBtn.MouseButton1Click:Connect(function()
	print(game.Selection:Get()[1])
end)
1 Like

You mean like a button to toggle the dock widget?

I think property is pluginGui.Enabled

1 Like

Thank you so much, Emerald!! I’ve got it working how I need.

Now that I’ve got all of this I should be able to get it to an actually useful plugin!!
(p.s. I don’t know what I’d mark as the solution to this post)

Thanks again!!

1 Like