How to scale UIGridLayout depending on how many pets u got

so I made a pet system, but the problem is that the uigridlayout and scrolling frame get maxed, i want to do a system where the scrolling frame and uigridlayout scale depending on how many pets u got

Im not going to type your whole script obviously, but basically just make a local to which’s value you set the current amount of pets of the player, after that, make a script with if statements
“local startergui = game:GetService(“StarterGui”)
if local petamount == [number] then
game.startergui.[yourscrollingguiname].size – set whatever size you want”

Try something like that^

ya but it wont work because i will have to do if statement for each number, i want it automatically scale

You could also do like a multiplier, like that you multiply size using the petamount value, try make a formula for this(if you try this method, dont forget to make a maxvalue)

ok thanks, but i dont really know math

To make it easy, just multiply the size by 1.05^petamount or 1.1^petamount

ok thank you i will try that – 30 char

Instead, you could try increasing the ScrollingFrame’s canvas size after x number of items have been added to the UIGridLayout, where x is UIGridLayout.FillDirectionMaxCells.

Use GuiObject.ChildAdded to see whether the child is a pet image, if it is then increment a variable by 1 so that when the variable reaches that x, it increases the ScrollingFrame’s CanvasSize like this

local frame = something.ScrollingFrame
frame.Size = frame.Size + Udim2.new(X, x, Y, y) -- you decide how much you want to increase the size and on what components
1 Like