So, I'm currently trying to make a Gui that has pages, I want to automatically make the right amount of buttons for each page, with the max amount of buttons on each page being 30.
By doing
local maxPages = math.ceil(#contents / 36)
with "contents" being the table of the items, I'm able to get the max amount of pages. Currently, I have 54 items, which would make this
local maxPages = math.ceil(54 / 36) -- equals to 2 pages
Onto the question, how would I know the exact amount of pages I would need for each page? Obviously, the first page would have 30, and the second would have 24, but how would I have the script automatically calculate this for me? I already have a script that'll make the buttons for me and position them accordingly.
This is a function that should do just that for you:
local function getPagesList(Amount, maxButtons) local maxPages = math.ceil(Amount / maxButtons) local PagesList = {} local Remaining = Amount for i = 1, maxPages do local maxAmount = math.min(Remaining, maxButtons) Remaining -= maxAmount table.insert(PagesList, maxAmount) end return PagesList end --Use examples: getPagesList(54, 30) --> {30,24} getPagesList(90, 20) --> {20,20,20,20,10} getPagesList(12, 5) --> {5,5,2} getPagesList(5, 10) --> {5}
Tell me if that doesn't work or if you don't understand something about the code (It's 2 am for me so I can't explain right now but hope I helped!)