Limit for Pages ( I think )

Hello. I’ve been doing a game, that involves player’s friends. And, there’s one problem I came up with.
Even if my profile has MORE than 100 friends, it gets only 100 of them.

local b = 0

local function getfriendid(page, plid)
	repeat
		local info = page:GetCurrentPage()
		for i, friendInfo in pairs(info) do
			b += 1
		end
		if not page.IsFinished then 

			page:AdvanceToNextPageAsync()
		end
	until page.IsFinished
end


local function getfriends(plri)
	local success, friendPages = pcall(function() return game.Players:GetFriendsAsync(plri) end)
	if success then
		return getfriendid(friendPages, plri)
	else
		return nil 
	end
end



wait(5)


getfriends(game.Players.BabyPennyB.UserId)


wait(5)

print(b)

Output this script gives is 100, and my profile has 146 friends.
What’s the deal? Is it the pages, or the GetFriendsAsync() function works incorrectly?
image

Have you tried the example on the Wiki? I believe it only allows you to pull 100 friends at a time, per page. (or something along the lines of)

“This code sample loads the Player.UserId of the player whose username is provided at the top of the script by using Players:GetUserIdFromNameAsync(). Then, it gets a FriendPages object by calling Players:GetFriendsAsync() and iterates over each entry using the iterPageItems function. The username of each friend is stored in a table, then printed at the end.”

local Players = game:GetService("Players")

local USERNAME = "Cozecant"

local function iterPageItems(pages)
	return coroutine.wrap(function()
		local pagenum = 1
		while true do
			for _, item in ipairs(pages:GetCurrentPage()) do
				coroutine.yield(item, pagenum)
			end
			if pages.IsFinished then
				break
			end
			pages:AdvanceToNextPageAsync()
			pagenum = pagenum + 1
		end
	end)
end

-- First, get the user ID of the player
local userId = Players:GetUserIdFromNameAsync(USERNAME)
-- Then, get a FriendPages object for their friends
local friendPages = Players:GetFriendsAsync(userId)
-- Iterate over the items in the pages. For FriendPages, these
-- are tables of information about the friend, including Username.
-- Collect each username in a table
local usernames = {}
for item, _pageNo in iterPageItems(friendPages) do
	table.insert(usernames, item.Username)
end

print("Friends of " .. USERNAME .. ": " .. table.concat(usernames, ", "))```
1 Like

I have a game which gets all friends of a player, here the script:

-- Server

local function iterPageItems(pages)
	return coroutine.wrap(function()
		local pagenum = 1
		while true do
			for _, item in ipairs(pages:GetCurrentPage()) do
				coroutine.yield(item, pagenum)
			end
			if pages.IsFinished then
				break
			end
			pages:AdvanceToNextPageAsync()
			pagenum = pagenum + 1
		end
	end)
end

-- Function to count items in FriendPages
local function countItems(pages)
	local count = 0
	for _ in iterPageItems(pages) do
		count = count + 1
	end
	return count
end

-- Example:
local userId = player.UserId
local friendPages = Players:GetFriendsAsync(userId)
local numFriends = countItems(friendPages)
1 Like

Thanks a lot! I should’ve read the Roblox Wiki more properly.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.