Hello. I am trying to make a “quick-search” system.
In this color picker, players can select a color by pressing one of the many colored buttons. If they scroll away, I want them to be able to click this:
and have the scrolling frame automatically scroll to the selected buttons position.
Here is the code I currently have. (Everything works in the code except getting the position of the identified button.)
function load()
local list = script.Parent.Parent.Parent.colors
local selection = script.Parent.Parent.Text
local s = list:FindFirstChild(selection)
print(selection,s.Name,s.Position.X.Offset)
if s then
local xpos = s.Position.X.Offset
list.CanvasPosition = Vector2.new(xpos,0)
end
end
script.Parent.MouseButton1Up:Connect(load)
I have already found the problem. I am using UIListLayout, which completely disables the position property of the GUI object inside of the scrolling frame.
Now, I need to figure out another solution that will let me get the position of the GUI inside of the scrollingframes canvas.
Label each frame 0 to the # of frames. 0 being the first frame and # frames being the frame farthest away. Do spaceBetweenEachFrame * position and position being what you labelled it. Add this number to the scrolling frames position
I just realized this is really late (saw it because it was bumped) but honestly for those who search for this:
local scroller : ScrollingFrame
local selectedButton : GUIButton
local scroller_absolute_position = scroller.AbsolutePosition
local current_canvas_position = scroller.CanvasPosition
local button_absolute_position = selectedButton.AbsolutePosition
local difference = button_absolute_position - scroller_absolute_position
scroller.CanvasPosition += difference
-- // You can tween this of course.
This also depends on your list method… but it should show up somewhere within the canvas.