How can i get a player's UserId on a FriendPage?

Hello!

I am looking at the documentation for FriendPages, but it’s very confusing and i did not understand it well.

I have this basic script:

game.Players.PlayerAdded:Connect(function(plr)
	local friends = game.Players:GetFriendsAsync(plr.UserId)
end)

All i want is to be able to have a function that gets one the player’s friends and returns their userId.

Code examples would help much better, thanks.

Pages are clunky as hell

To retrieve the current page’s data, use GetCurrentPage, this will return an array that you can use to retrieve various data points

A FriendPages’s data will look along the lines of

{
  {
    Id = 8094244,
    IsOnline = true,
    Username = "metatablecatmaid"
  },

  {
    Id = 1,
    IsOnline = false,
    Username = "Roblox"
  }
}

To go to the next page, use AdvanceToNextPageAsync, UNLESS IsFinished is true, in which case, assume that all data in the Pages object has been handled

1 Like

Everytime i use the :GetFriendsAsync() will it return the same player or will it have different players?

And also, is each page is a different friend?

Each page will have the same number of objects in it (idk what it is, but it’ll be 10, 25 or 100)

Do not rely on the order of the pages to be consistent, since it pulls its data from a Web API

So each time i call the function it will be a different player or the same one?

NextPage returns the next 10 or so objects, data wont be duplicated in a single FreindsPages object.

image
Ok, each page returns with 50 friends.

I just used a print for this, how do i get the player’s Id now?

Did you print a ‘page’ object itself?

do
	local Success, Result = pcall(function() Players:GetFriendAsync(1) end)
	if not Success then warn(Result) return end
	local Page = Result:GetCurrentPage()
	repeat
		for Index, PageItem in ipairs(Page) do
			print(PageItem.Id) --Index page item's 'ID' field.
		end
		
		if not Result.IsFinished then Result:AdvanceToNextPageAsync() end
	until Result.IsFinished
end

Once you’ve retrieved a single ‘page’ from the ‘pages’ object you can iterate over its items and print each item’s ‘Id’ field.