So I have an inventory GUI. When items are added the canvas size of the scrolling frame increases. Unforunately, when this happens it affects the size and position of the buttons.
I just need to know how I'd calculate the size and the position of the button so it looks like the same size and is spaced out the same no matter what the size of the canvas is.
This is what I've tried. I can't get the math right.
local getInventory = player.Inventory:GetChildren()
for i,Item in pairs(getInventory) do
if Item.ClassName == "IntValue" then
local button = Instance.new("TextButton",GUI.Inventory.InventoryList)
button.Size = UDim2.new(0.925,0 (0.055/GUI.Inventory.InventoryList.CanvasSize.Y.Scale),0)
button.Position = UDim2.new(0.025,0,(PositionUI + 0.015),0)
PositionUI = PositionUI + 0.065/GUI.Inventory.InventoryList.CanvasSize.Y.Scale
end
end
PositionUI = 0

5 comments
please indent your code, it makes things easier
He did, but the website's lua code block doesn't allow the code to go off the screen, so they put it on the next line.
Take a look at UIGirdLayouts and UIListLayouts. They perform the maths for you with the tradeoff of taking some setup
Use offset.
Ah. Using offset worked, thanks.