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.

2 comments
Sata's is right, if you don't want to do it all in a for loop, but would prefer to go one page at a time though, I would suggest you use math.min(30, #contents - 30 * pageNumber)
Only reason sata's might not be good is if you're doing 80000 pages and only need the first 1, then it's inefficient to do the whole for loop