local function IterPageItems(pages)
return coroutine.wrap(function()
local PageNumber = 1
while true do
for _, item in pages:GetCurrentPage() do
coroutine.yield(item, PageNumber)
end
print(pages:GetCurrentPage())
if pages.IsFinished then
print("FINISHED")
break
end
print("NEXT PAGE")
pages:AdvanceToNextPageAsync()
PageNumber += 1
end
end)
end
local Success, FriendPages = pcall(function()
return Players:GetFriendsAsync(Player.UserId)
end)
if Success then
print(IterPageItems(FriendPages)) -- Only prints a table of 50?
end
Maybe there’s a limit on how many pages can be advanced in a given time, similar to the limits of other services such as MarketPlaceService calls? Otherwise, I’m not sure. But if that is the case, you can just check if it failed and then repeat attempts with a delay until it goes through.
It doesn’t fail tho. IT does 50 pages then pages.IsFinished is set to true. And there no way to know if it’s “actually” finished, cause I need to use this to get how many friends I have, which again, is falling short
Hello! I tested your script and it works with some improvements, i used this code:
local Players = game:GetService("Players")
local function IterPageItems(pages)
local List = {}
while true do
print(pages:GetCurrentPage())
table.insert(List, pages:GetCurrentPage())
if pages.IsFinished then
print("FINISHED")
break
end
print("NEXT PAGE")
pages:AdvanceToNextPageAsync()
end
return List
end
local Success, FriendPages = pcall(function()
return Players:GetFriendsAsync(15619704) --Your UserId
end)
if Success then
print(IterPageItems(FriendPages)) -- Only prints a table of 50?
end
I changed almost nothing, maybe problem was in coroutine?
(I don’t know what coroutine exactly is)
I think that was indeed the issue, likely the way it was being used.
You can learn more about it here:
I’m not exactly sure why it was being used in this case.
Although, I would change the array to contain friends rather than the page number:
local function IterPageItems(pages)
local Friends = {}
local PageNumber = 1
while true do
for _, item in pages:GetCurrentPage() do
table.insert(Friends,item)
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
end
return Friends
end
local Success, FriendPages = pcall(function()
return Players:GetFriendsAsync(Player.UserId)
end)
if Success then
print(IterPageItems(FriendPages))
end