Getting position of GUIs in a scrollingframe canvas

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:
image
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.

Try using GUI.AbsolutePosition

That gets the gui position according to the players screen, not the scrolling frame.

Are you using offset to position your UI?

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 mentioned in my post that I am using a UIListLayout to store all of the buttons. That completely removes the position property from being used.

why don’t you make them not visible with a for when searching with based on the color button that has less characters?

1 Like

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.

3 Likes

thank you so much for your reply, but i forgot to say that i didn’t need a solution anymore, it has been a while lol

i will mark your answer as a solution for anybody else who comes by.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.