Getting the player's friends in a server

I hope that the title says it all if not then what i want is that i want every single friend of the player in the server. Thats all

2 Likes

Just change the game server options.
Like there will be a option, were only your friends can join your server.

And your topic doesn’t match with the category.

UMM?? Bro did you even see what i said? and also the server is public thats non-sense

Care to explain why?

local players = game:GetService("Players")
local localPlayer = players.LocalPlayer

local friendsWith = {} --array of player instances the local player is friends with

for _, player in ipairs(players:GetPlayers()) do
	if player ~= localPlayer then
		local success, result = pcall(function()
			return localPlayer:IsFriendsWith(player.UserId)
		end)
		
		if success then
			if result then
				table.insert(friendsWith, player)
			end
		else
			warn(result)
		end
	end
end
2 Likes

if i wanted that i would never make this topic

Local script inside StarterPlayerScripts folder.

There’s also the following method but for this use-case it isn’t as efficient.

https://developer.roblox.com/en-us/api-reference/function/Player/GetFriendsOnline

1 Like

If you want to get all the player’s friend. You can use HTTP and use GET to get the data from Roblox API. Here’s the Roblox API doc for friends, Friends Api

Specifically, to get all the player’s friend, here is the specific API:-
https://friends.roblox.com/v1/users/1168378543/friends

Just change the UserId to the player UserId in game that you want to search all their friends off.
You need to use a proxy since Roblox doesn’t allow making request off their own servers.
Roproxy is a reliable proxy, so you can just do it like this:-
https://friends.roproxy.com/v1/users/1168378543/friends

By getting their friends, that means you get the friends’ current data. Here’s an example of the data of a friend of mine

 {
      "isOnline": false,
      "presenceType": 0,
      "isDeleted": false,
      "friendFrequentRank": 1,
      "description": null,
      "created": "0001-01-01T06:00:00Z",
      "isBanned": false,
      "externalAppDisplayName": null,
      "id": 135246762,
      "name": "Embossed2",
      "displayName": "LannisUltraBard"
    }

Solution: O ye I was complicating things and didn’t realize that there’s a simple function for that
https://developer.roblox.com/en-us/api-reference/function/Players/GetFriendsAsync

Basically gets the player’s all Friend, online or offline

1 Like
local players = game:GetService("Players")
local localPlayer = players.LocalPlayer

local friendsWith = {} --array of player instances the local player is friends with

local success, result = pcall(function()
	localPlayer:GetFriendsOnline(200)
end)

if success then
	if result then
		for _, friend in ipairs(result) do
			if friend["IsOnline"] then
				if friend["GameId"] == game.JobId then
					local player = players:FindFirstChild(friend["UserName"])
					if player then
						table.insert(friendsWith, player)
					end
				end
			end
		end
	end
end

Here’s an alternate solution with the other method I provided.

3 Likes