Hello Developers!
I have 2 GUI objects/elements inside of my project. I have a button that, when pressed, will move a frame to the button’s position. My problem: The button is placed under a UIGridLayout
.
I have tried creating a separate “parent” frame for the button and getting the position that way, however, that has not worked.
I stumbled across AbsolutePosition
on my journey through the internet and have attempted that as well. The code so far:
-- Location of elements
local Frame = Button.Parent.Frame
local Button = script.Parent
-- Getting the absolute position of the button
local OffsetX = Button.AbsolutePosition.X
local OffsetY = Button.AbsolutePosition.Y
Button.MouseButton1Down:Connect(function())
Frame.Position = UDim2.new(0.5, OffsetX, 0.5, OffsetY)
end)
The AnchorPoint
of both elements is (0.5, 0.5).
Any and all help is greatly appreciated! Thank you!
EDIT: To clarify, the code above does not work. The frame’s position does not match the button’s when the button is pressed.
9 Likes
I would have an invisible frame above the frame with the uigridlayout and have the frame that moves inside of that, so its position is not overwritten by the uigridlayout
6 Likes
The only problem is that there are multiple buttons. This wasn’t shown (my bad) but the button and the button press are being detected through for loops, essentially looping through all of the buttons until one is pressed, then setting the frame’s position to the position of the button. All of the button’s positions are at (0.5, 0, 0.5, 0) even though they aren’t actually positioned there (thanks to the UIGridLayout
).
Thank you for the reply!
5 Likes
I don’t think you’ll need the .5 in the scale of the UDim2 that you’re moving the frames position then, it should work to just change the offset to the absoluteposition of the button
4 Likes
I just updated the code and tested it. The same result is still occurring. The position is being changed, however, it is way off from where the button is.
3 Likes
is the selection frame still parented to the frame with the uigridlayout?
3 Likes
Above is the placement. The “AppCover” frame is what is being positioned.
Under the “Homepage” is the UIGridLayout
along with the buttons. Each button has a parent frame. I am getting the position of the parent frame currently.
EDIT: I just tried to get the position of the actual button and that also did not work.
3 Likes
I think the uigridlayout is just the main problem here with the positioning. instead of moving the appcover frame, could you try just having a similar frame inside each button, and change its visibility when its parent is clicked? there would be no positioning involved and I think it would match the effect you’re trying to get
2 Likes
I would agree, the UIGridLayout
is the main issue. I need the “AppCover” frame to be positioned though. If there is any way to do exactly that, that would be amazing!
Thank you so much for your help @CullWasHere! Let me know if you have any other ideas for positioning the frame. Otherwise, this topic is still in need of an answer.
2 Likes
I’m not sure exactly why the frame would need to be positioned differently if it were inside each button (position 0,0,0,0 size 1,0,1,0) unless my idea of the appcover is wrong.
1 Like
Because I don’t want to create an “AppCover” frame for every app is essentially the reason for that…
1 Like
alr that’s fine, that’s just how I would do it. hopefully someone else can come up with a solution for you
1 Like