Getting a player's friend count

I’m working on a script that prints out the amount of friends a specified user has. The issue is that it stops at 50 friends everytime, even if the player has more than 50 friends. Anyone know how to fix this?

local friendsArray = {}
	local friendCount = 0
	
	local success, page = pcall(function() return Players:GetFriendsAsync(targetUserId) end)
	if success then
		repeat
			local info = page:GetCurrentPage()
			for i, friendInfo in pairs(info) do
				table.insert(friendsArray, friendInfo.Id)
			end
			if not page.IsFinished then 
				page:AdvanceToNextPageAsync()
			end
			task.wait()
		until page.IsFinished
	else
		print("Failed to get friends")
	end
	
	for _, friend in friendsArray do
		friendCount += 1
		task.wait()
	end
	print(friendCount)

you have to go to the next page and get them too

1 Like

I’m not sure how to do that

(character limit)

check out the code example

2 Likes

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