:GetFriendsAsync only gets 50 off my friends

Hey! So, i am currently working on a game where i’ll be in need off getting every friend a player has. In order to do that, i would need to use the :GetFriendsAsync function. Although it works and gets some off my friends, it only gets 50 off them. I have 78 friends on roblox, how would i make it get all of them?

This is my code.


game.ReplicatedStorage.StartFriends.OnServerEvent:Connect(function(Player)
	
	
	local Character = Player.Character or Player.CharacterAdded:Wait()
	
Player:FindFirstChild("InMenu").Value = false

	local players = game:GetService("Players")
	local PlayerUI = game.ServerStorage.PlayerUI.MainPlayer:Clone()
	
	if Player.UserId == game.CreatorId then
		PlayerUI.Frame.Developer.Visible = true
	else
		PlayerUI.Frame.Developer.Visible = false
	end
	
	
	
	PlayerUI.Adornee = Character:WaitForChild("Head")
	PlayerUI.Parent = Character
	PlayerUI.MaxDistance = 50
	local friendsId = Player.UserId
	local PlayersFriends = {}
	local Click = script.Click:Clone()
	Click.Parent = Character:FindFirstChild("Head")
	local success, page = pcall(function() return players:GetFriendsAsync(friendsId) end)
	if success then
		repeat
			local info = page:GetCurrentPage()
			for i, friendInfo in pairs(info) do
				table.insert(PlayersFriends, friendInfo)
			end
			if not page.IsFinished then 
				page:AdvanceToNextPageAsync()
				print("advanced")
			end
		until page.IsFinished
	end


	while true do
		wait(1)
		if not Character then break end
if Character:WaitForChild("Humanoid").Health <= 0 then break end


		local leaderstats = Player:WaitForChild("leaderstats")
	

		for i,v in pairs(PlayersFriends) do
			if not Character then break end
			if Character:WaitForChild("Humanoid").Health <= 0 then break end
			if Player:WaitForChild("CanSeeFriends").Value == true then
				leaderstats:FindFirstChild("Friends").Value = #PlayersFriends
				PlayerUI.Frame.Friends.Text = "Friends With: "..v.Username
				if Character:FindFirstChild("Head"):FindFirstChild("Click") then
					Character:FindFirstChild("Head"):FindFirstChild("Click"):Play()
				end
				wait(1)
				print("changed")

			else

				leaderstats:FindFirstChild("Friends").Value = 0
				PlayerUI.Frame.Friends.Text = "[HIDDEN]"
			end

		end

	end



	
	
	
end)


2 Likes

i think the issue is here, try to make it 200 or 100 and test it out
image

Sadly, it did not work. I’m using a billboardgui to display the friends name and avatar, and this was the max distance on how far away you can see it from.

Heyo, I whipped this up quite quickly, though you could give it a try:

-- services
local players: Players = game:GetService("Players")

-- variables
local userId: number = 1255193394

-- declare a nil variable for later use
local friends: any

-- using a pcall in case the function fails
local success: boolean, errorMessage: string = pcall(function()
	friends = players:GetFriendsAsync(userId)
end)

-- if there was an error, print it and return nil
if (not success) then
	warn(errorMessage)
	
	return
end

-- a function to iterate through the 'FriendPage(s)'
local function IterateBook(pages: any)
	return coroutine.wrap(function()
		local pagenumber: number = 1
		
		while (true) do
			for index: number, item: string in ipairs(pages:GetCurrentPage()) do
				coroutine.yield(item, pagenumber)
			end
			
			if (pages.IsFinished) then
				break
			end
			
			pages:AdvanceToNextPageAsync()
			pagenumber += 1
		end
	end)
end

-- this table stores all the information about your friends
local tableOfFriends: any = {}

-- convert the 'IterateBook' function into actual data
for item: any, page: any in IterateBook(friends) do
	tableOfFriends[#tableOfFriends + 1] = item
end

-- print all the information
print(tableOfFriends)

It’s a very basic friend retrieval script. Uses the function on the documentation to iterate through what I rewrote as a ‘book’. This ‘book’ stores all the pages, aka, your friend data. You can sort of ‘convert’ it into a table which you can use later down the line.

Tested it out, it works perfectly! Thank you!

1 Like

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