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:
(Label is what your username would be, it’s just a template)
Here’s the explorer too:
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()
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!
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
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
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