How can i know if the player is friends with someone that they in the same server on custom leaderboard?

Im unable to find anyone making custom leaderboard with checking if friend and I don’t know how to check if friends because I wanna make the image label to a friend icon but I don’t know how to check if the player is a friend and show it on the own user if they are friends with and please anyone help CUSTOM LEADERBOARD local script

local LeaderboardGui = game.Players.LocalPlayer.PlayerGui:WaitForChild("MainClient")
local PlayerListScroll = LeaderboardGui.PlayerList

local Leaderboard = game:GetService("ReplicatedStorage").TextLabel

local Player = game.Players.LocalPlayer

--local IsFriend = Player:IsFriendsWith(UserId)-- 10885655986
-- Function to update the leaderboard with the current player scores
local function updateLeaderboard()
	-- Get the list of players
	local players = game.Players:GetPlayers()
	-- Sort the list of players by their score in descending order
	-- Clear the existing player list
	PlayerListScroll:FindFirstChild("PlayerEntry")
	-- Add each player to the leaderboard
	for i, player in ipairs(players) do
		-- Create a new leaderboard entry for the player
		local playerEntry = Leaderboard:Clone()
		--local playerEntry = Instance.new("TextLabel")
		--local badge = Instance.new("ImageLabel")
		
		playerEntry.Name = "PlayerEntry"
		--playerEntry.Size = UDim2.new(0.491, 0, 0, 31)
		--playerEntry.Position = UDim2.new(0, 0, 0, (i-1)*30)
		--playerEntry.BackgroundTransparency = 1
		--playerEntry.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
		--playerEntry.BorderSizePixel = 0
		--playerEntry.TextColor3 = Color3.fromRGB(255, 255, 255)
		--playerEntry.TextScaled = true
		--playerEntry.Font = Enum.Font.SourceSans
		playerEntry.Text = player.Name
		playerEntry.Parent = PlayerListScroll
		--if Player.UserId == game.CreatorId then
		if Player.UserId == 3371429392 then
			playerEntry.ImageLabel.ImageTransparency = 0
			playerEntry.ImageLabel.ImageColor3 = Color3.new(1, 1, 1)
		elseif Player.UserId == 1 then
			playerEntry.ImageLabel.ImageTransparency = 0
			playerEntry.ImageLabel.Image = 'rbxassetid://10885637246'
			playerEntry.ImageLabel.ImageColor3 = Color3.new(1, 1, 1)
		elseif Player.UserId == 409022436 then
			playerEntry.ImageLabel.ImageTransparency = 0
			playerEntry.ImageLabel.Image = 'rbxassetid://12626962506'
		elseif  then
			
			
		end
	end
end


updateLeaderboard()

You can use player:IsFriendsWith(userId) for this purpose.

well i did use but i dont know how to make change from the other people

Create a variable equal to a table. Then, loop through whatever you’re trying to find the player’s friends. Use :IsFriendsWith, then, if player is a friend insert their username into the table.

2 Likes

well thats some leveling scripting

1 Like

Here’s an example.

local friendsTable = {}

for i, v in pairs(example:GetChildren()) do --Loop through whatever your trying to find the player’s friends

if v.Name:IsFriendsWith(playerVariable) then

table.insert(friendsTable, v.Name)

1 Like