Friend icon in custom player list not working correctly

So I have a custom player list in my game and I have it so that it puts an icon next to the friends name when they’re in the game the only problem is its putting it on the friends name and my name (not sure if it would put it for everyone in the game even if you aren’t friends with the person and I cant rlly test that but still) ill link the photo:

So my name is iclimbedwall and my friend is leahpufff but I want it to show the icon for leahpufff (the person I’m friends with) only, not both of us. How can I make that work? Here’s the script for the player list it has the friend part in it.

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
	
	local localPlayer = players.LocalPlayer
	local friend_icon = script:WaitForChild("FriendIcon")

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

		if not isFriends then
			continue
		end

		friend_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()

The friend icon part is below

local localPlayer = players.LocalPlayer
	local friend_icon = script:WaitForChild("FriendIcon")

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

		if not isFriends then
			continue
		end

		friend_icon:Clone().Parent = listed
	end

The friend icon is parented to this script too and there is a template for the label (listed); ill show my explorer anyway
Screen Shot 2021-05-24 at 7.34.16 PM
ListPlayers is the player list and the template is the text label that shows your name

[quote=“iclimbedwall, post:1, topic:1250330, full:true”]
So I have a custom player list in my game and I have it so that it puts an icon next to the friends name when they’re in the game the only problem is its putting it on the friends name and my name (not sure if it would put it for everyone in the game even if you aren’t friends with the person and I cant rlly test that but still) ill link the photo:

So my name is iclimbedwall and my friend is leahpufff but I want it to show the icon for leahpufff (the person I’m friends with) only, not both of us. How can I make that work? Here’s the script for the player list it has the friend part in it.

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
	
	local localPlayer = players.LocalPlayer
	local friend_icon = script:WaitForChild("FriendIcon")

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

		if not isFriends then
			continue
		end

		friend_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()

The friend icon part is below

local localPlayer = players.LocalPlayer
	local friend_icon = script:WaitForChild("FriendIcon")

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

		if not isFriends then
			continue
		end

		friend_icon:Clone().Parent = listed
	end

The friend icon is parented to this script too and there is a template for the label (listed); ill show my explorer anyway
Screen Shot 2021-05-24 at 7.34.16 PM
ListPlayers is the player list and the template is the text label that shows your name

hopefully i get a response this time :sob:

1 Like

I think you could add a simple if statement here that checks if the found player is not the player themselves

	if table.find(developerIds, players:GetUserIdFromNameAsync(name)) and table.find(developerIds, players:GetUserIdFromNameAsync(name)) ~= localPlayer  then
		dev_icon:Clone().Parent = listed
	end

The if statement is for the friend icon not the dev icon so how should I do it

The friend code that should have the if statement or whatever it needs is here

1 Like

That should work. It stops the script if the player is “user”.

Oh because I tested it like that and it still didn’t work it showed the friend icon for me and my friend is there another way that could work?

1 Like

Hmm. Are there any error messages? Also, try using

if localPlayer == user then return end

I haven’t really encountered continue before (that’s not to say it’s not viable!), but try using return in this specific case instead.

I tested it in a for loop in studio and it didn’t end the loop. Here was my code:

for i = 1, 10, 1 do
	
	if i==5 then continue end
	
	print(i)
end

The output went all the way up to ten.

1 Like

You could just do “if localPlayer ~= user then
–continue
end”

2 Likes

That works too. Learned something new today!

2 Likes

do this maybe:

local temp = script.Template
local friend_Icon = script.FriendIcon

if temp.Text == script.Parent.Parent.Parent.Parent.Name then
    temp:Destroy()
    friend_Icon:Destroy()
end
1 Like

No problem fellow programmer :slight_smile:

2 Likes

Well i would just destroy the friend icon bc i dont want the template to destroy as well

Then delete temp:Destroy() :grinning_face_with_smiling_eyes:

1 Like