I don't understand AnchorPoint or Position well enough to figure out how to get a GUI to remain in a constant relative position despite my screen size. I am trying to make an inventory GUI that tweens out from the left edge of the screen (meaning most of it shouldn't be visible when its not opened); however, when I stretch my window to a different size, the part of the GUI that should be hidden beyond the left edge becomes visible. How would I go about fixing this? Here is my code if that means anything:
01 | local TweenService = game:GetService( "TweenService" ) |
02 | local inventory = script.Parent.Parent |
03 |
04 | function onClicked(GUI) |
05 | local openGoal = { } |
06 | openGoal.Position = UDim 2. new( 0.02 , 0 , . 5 , 0 ) |
07 | local closeGoal = { } |
08 | closeGoal.Position = UDim 2. new(- 0.1 , 0 , . 5 , 0 ) |
09 |
10 | local tweenInfo = TweenInfo.new( 2 ) |
11 | local openInventory = TweenService:Create(inventory, tweenInfo, openGoal) |
12 | local closeInventory = TweenService:Create(inventory, tweenInfo, closeGoal) |
13 |
14 | local curr_pos = inventory.Position |
15 |
One way do keep a GUI in the middle of a screen no matter the device is to set AnchorPoint to 0.5, 0.5 and Position should be set to {0.5, 0},{0.5, 0} this way centers your GUI in every devices screen no matter the size of the device. Hope this helps!