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.
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.
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)