Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Getting the friends of a player?

Asked by 7 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.

Thanks.

3 answers

Log in to vote
8
Answered by 7 years ago
Edited 7 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).

Example:-

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

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

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.

Ad
Log in to vote
1
Answered by 7 years ago
Edited 7 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 roblox.com domain, you may use a proxy such as rprxy.xyz 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("https://api.rprxy.xyz/users/" .. 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.
end

I hope my answer helped you.

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

0
NOTE: Completely forgot ROBLOX blocks requests to their website, I'll edit my answer to reflect this. Spongocardo 1991 — 7y
0
i cant find httpservice in my friends list :( greatneil80 2647 — 4y
Log in to vote
0
Answered by
brianush1 235 Moderation Voter
7 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 roblox.com through HttpService

Answer this question