How to make a friend icon appear next to username in custom player list

I have a custom player list and I wanted to make it so that when you’re friends with another player, it says that next to their name like this:
Screen Shot 2021-05-23 at 3.49.15 PM (Label is what your username would be, it’s just a template)
Here’s the explorer too:
Screen Shot 2021-05-23 at 3.52.50 PM

I’ll link the script that controls the player list too (it has a line that makes an icon similar to this appear if you are a developer, but I haven’t done the friend one yet in the code because I don’t know how):

local userinput = game:GetService("UserInputService")
local startergui = game:GetService("StarterGui")
local players = game:GetService("Players")
local listframe = script.Parent
local playerlist = listframe.ListPlayers

--default list disable, remove if you're already doing this
repeat
	local load = pcall(function()
		startergui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
	end)
	wait(0.2)
until load

local dev_icon = script:WaitForChild("DevIcon");
local developerIds = {
	1822194589,
	505994310,
	883317228,
};

local function makebox(name, current)
	local listed = script.Template:Clone()
	listed.Parent = script.Parent.ListPlayers
	listed.Position = UDim2.new(0.032,0,0.013,current*60)
	listed.Name = name
	listed.Text = name

	--you can use your own values here
	listed.BackgroundColor3 = script.Parent.ListTitle.BackgroundColor3
	listed.TextStrokeColor3 = script.Parent.ListTitle.TextStrokeColor3
	listed.TextStrokeTransparency = 0
	listed.Size = UDim2.new(0.929, 0, 0.072, 0)
	listed.TextScaled = true
	listed.TextColor3 = Color3.new(1, 1, 1)
	listed.Font = "GothamSemibold"
	local Corner = Instance.new("UICorner", listed)
	
	if table.find(developerIds, players:GetUserIdFromNameAsync(name)) then
		dev_icon:Clone().Parent = listed
	end

end


local function reload() --this reloads the player list when called
	for _,v in pairs(playerlist:GetChildren()) do
		v:Destroy()
	end
	for _,v in pairs(players:GetChildren()) do
		makebox(v.Name, #playerlist:GetChildren())
	end
end

local isActive = true
userinput.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Tab then --will show/hide with tab
		if not isActive then
			reload() --updates on tab press
			isActive = true
			listframe.Visible = true
		else
			isActive = false
			listframe.Visible = false
		end
	end
end)

while true do
	wait(0.1)
	reload()
end

--updates on player join/leave
players.PlayerAdded:Connect(reload)
players.PlayerRemoving:Connect(reload)

reload()
2 Likes

You need to use HttpService and enter the roblox friends API

I’m not that good at doing stuff like this how would I use the API and stuff like that I dont really know too much about APIs and services

Me Either :grinning_face_with_smiling_eyes:

1 Like
local TableOfFriends = Game.Players:GetFriendsAsync(userId)

For every user it returns

Reference Type Description
Id int64 The friend’s UserId
Username string The friend’s username
DisplayName string The display name of the friend.
IsOnline bool If the friend is currently online

Therefore you can do a loop through.

for _,FriendObj in pairs(TableOfFriends) do
    for _,PlayerObj in pairs(game.Players:GetChildren()) do
        if PlayerObj.UserId == FriendObj.Id then
            print("pog, we've found a match")
            -- add them to the GUI
        end
    end
end

This can be done with 2 methods that you’ll need of course. First you need Players:GetFriendsAsync(userid) and the Players:GetUserThumbnailAsync(userid), with the return from the first method (since it returns the userid, the username, the displayname and a boolean) we can get the thumnail for that player!

Here’s a good resource: FriendPages | Roblox Creator Documentation

1 Like


UserId is underlined how do I fix this

Define it. Wherever the player is defined, you just do UserId = Player.UserId

You can use GetFriendsAsync or IsFriendsWith

local localPlayer = players.LocalPlayer

for _, user in pairs(Players:GetPlayers()) do
local isFriends = user:IsFriendsWith(localPlayer.UserId)

if not isFriends then
continue
end

-- do stuff
end

Okay so where it says do stuff is that where I parent the icon to the friend’s username?

Yep.


If listed is the text label with the player’s username on it, would I just parent the icon to that or is it not going to work that way

It would work depends on how your ui parenting is sorted out.

Ok I’ll try because I have the friend icon and the template which shows your username in the list parented to the list script

so io tested it with 2 people and both me and my friend had the friend icon I just want the friend icon to be on the player I’m friends with because it would be weird if it was like how it is now and im afraid that it might show the icon for every player if I’m friends with one person like this

Sorry for the late response but maybe try checking if the player in the loop is the localplayer, if the player is then continue the loop.

local localPlayer = players.LocalPlayer

for _, user in pairs(players:GetPlayers()) do
if localPlayer.UserId == user.UserId then continue end
local isFriends = user:IsFriendsWith(localPlayer.UserId)

if not isFriends then
continue
end

friend_icon:Clone().Parent = listed
end
1 Like

Still doesn’t work (I want it to just have the friend icon under leahpufff’s name, not under mine.)
Screen Shot 2021-05-23 at 9.14.30 PM

@flkfv btw when the friend leaves I lose the friend icon which is good but I just don’t want the friend icon on my name because I don’t need it yk

Let me know if this works:

local plr = game.Players.LocalPlayer
for _, i in pairs(players:GetPlayers()) do
	if i.UserId == plr.UserId or not i:IsFriendsWith(plr.UserId) then
		continue
	end
	local clone = friend_icon:Clone(); clone.Parent = listed
end
2 Likes

ill try it with a friend in studio and ill let yk if it works