Still have questions? Join our Discord server and get real time help.
Log in to vote

Getting the friends of a player?

Asked by 2 years ago

Is there a way to get all the friends of a player on roblox? Not just the ones that are online, but all of them in total. I know this is possible, as I saw it done in pokemon brick bronze, where when you click the follow friend feature and look at the output you can see the names of all your friends as well as their userid and which server they are in if they are online. It would be great if this could be in a table, aswell.

Im trying to use this in order to create a score comparing-system, where I would check if the friend has a datastore and look into it to get their best score.


3 answers

Log in to vote
Answered by
kingdom5 5316 Trusted Snack Break Moderation Voter Community Moderator
2 years ago
Edited 2 years ago

You do not need to use the http service to do this task as there are functions available to use which allows us to get all of the players friends (both online and offline).


local tblPrint = require(script.Parent.tablePrint) -- just my table print module

    local page = game.Players:GetFriendsAsync(plr.UserId) -- the user id of the player we want to get their friend 
        if not page.IsFinished then page:AdvanceToNextPageAsync()end -- we cannot get the next page if this is the last page
    until page.IsFinished 

This uses the function GetFriendsAsync and passes back the following information in the form of a page:-

  • Id number The UserId of the friend.

  • Username string The Username of the friend.

  • IsOnline boolean If the friend is currently online.

Log in to vote
Answered by 2 years ago
Edited 2 years ago

HttpService is your friend

You can use the HttpService to get all the friends the user has. Using the ROBLOX API, you can send a get request which returns the user's friends in a JSON format that can be decoded to be used in your code as a normal array.

Since you can't make HTTP requests to the domain, you may use a proxy such as to make these HTTP requests.

Here's an example link that returns a list of Shedletsky's friends.

You can also find documentation for this API here.

To use this in a script, you have to enable the HttpEnabled property which can be found in the HttpService in the explorer menu.

From there, you will be able to make HTTP requests. Here's an example which prints all of Shedletsky's friends into the output window:

Be sure that you make HTTP requests in a server script instead of a local script, otherwise this will not work.

local http = game:GetService("HttpService") --Variable that holds a reference to the HTTP service.
local id = 261 --This is the ID of the user. This can be found in the player under the UserId property.

local friends = http:GetAsync("" .. id .. "/friends",true) --We can use concatenation to add the id variable into the link. The true value is to make sure that old results aren't used if we've already requested from the link before (AKA caching).
friends = http:JSONDecode(friends) --Decode the JSON array that's returned from the request so the script can read it.

for i = 1,#friends do --Run this loop depending on how many entries there are in the table.
    print(friends[i]["Username"]) --Prints each username into the console.

I hope my answer helped you.

EDIT: Fixed code and links to show that ROBLOX APIs can be accessed through a proxy.

NOTE: Completely forgot ROBLOX blocks requests to their website, I'll edit my answer to reflect this. Spongocardo 1941 — 2y
Log in to vote
Answered by
brianush1 200 Moderation Voter
2 years ago

This cannot be done through ROBLOX's player API, but it can be done with external HTTP API's. A sample link would be this and would return a JSON table of the user's first 20 friends.

  • Note that external API's must be used to access through HttpService

Answer this question