Perfect! Here’s a small break-down of what I did to achieve this, and why I did those steps. For ease of understanding, I will be referring to ChatGui.ChatBG
as ‘main frame’. If anything I’ve explained is unclear, feel free to ask me to elaborate!
• 1. I set the AnchorPoint
of the main frame to 0, 0.5
. This places the the anchor point here
With the anchor point placed here, we can place the UI precisely in the center of the screen by setting Size.Y.Scale
to 0.5. This means the main frame will be positioned at 50% of the height of its parent element. In this case, that element is a ScreenGui, which will be your entire viewport.
Then I set the X value of the position to 0, 10
. This places the main frame at 10 pixels from the border of the screen.
The final position value now reads 0, 10, 0.5, 0
. This is our Open
position
• 2. I changed the value names frameStartPosition
and frameEndPosition
to frameOpenPosition
and frameClosePosition
respectively. This improves readability a little bit in case you need to come back to this code at a later date.
• 3. I changed the frameOpenPosition
by copying and pasting the current Position value from the main frame.
• 4. I determined the desired position for the main frame when it’s closed. Since an X-position of 0, 10
places it at 10 studs to the right relative from the left-side edge of the screen, I wanted the closed position to be to the left relative to the edge of the screen. (This would be off-screen). The exact position would be an inverse of the X-scale of the main frame. In this case, the X-scale is 0.353, 0
, so the desired X-position when the main frame is closed is -0.353, 0
.
In order for our code to automatically adapt to any future changes to the UI’s size, I’ve opted to determine the closed position variable like this:
local frameClosePosition = UDim2.new(-frame.Size.X.Scale, 0, 0.5, 0)
• 5. After a first test run, I noticed that the background image of the main frame is in fact scaled past its own borders, making the main frame stick out on the left side. I solved this by giving the closed position variable a small offset of -4.
• 6. I also noticed that the open/close button was clipping with the rest of the UI a little bit.
I fixed this by giving the button a small offset of 2 pixels on its X-position.
The final result can be seen in the video I posted previously!