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:
local TweenService = game:GetService("TweenService") local inventory = script.Parent.Parent function onClicked(GUI) local openGoal = {} openGoal.Position = UDim2.new(0.02, 0, .5, 0) local closeGoal = {} closeGoal.Position = UDim2.new(-0.1, 0, .5, 0) local tweenInfo = TweenInfo.new(2) local openInventory = TweenService:Create(inventory, tweenInfo, openGoal) local closeInventory = TweenService:Create(inventory, tweenInfo, closeGoal) local curr_pos = inventory.Position if curr_pos.X.Scale <= -.09 then openInventory:Play() else if curr_pos.X.Scale >= 0.019 then closeInventory:Play() end end end script.Parent.MouseButton1Click:connect(onClicked)
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!