Recently I have started a new project and I have started making the GUI for the game and as I was making the main menu screen I had wanted to make a bar on the side of the players screen to see if there friends were online and in the game so they could party up with them, but after a few attempts at making the script I have gotten further but can reach the end.
The code is below right now it is able to clone the imagelabel the only issue is the image it doesn’t use the friends id only the local players… If that makes sense.
Here is what I mean each one of those images is cloned at it is supposed to, but they are supposed to be the all of the local players friends image not my own.
local players = game:GetService(“Players”)
game.ReplicatedStorage.PlayersFriends.OnServerEvent:Connect(function(player, plrId)
local friendsId = plrId
local PlayersFriends = {}
local success, page = pcall(function()
return players:GetFriendsAsync(friendsId)
end)
if success then
repeat
local info = page:GetCurrentPage()
for i, friendInfo in pairs(info) do
table.insert(PlayersFriends, friendInfo)
end
if not page.IsFinished then
page:AdvanceToNextPageAsync()
end
until page.IsFinished
end
local sideMenuBackground = player.PlayerGui.MainMenu.SideMenu.Background
local thumbType = Enum.ThumbnailType.AvatarBust
local thumbSize = Enum.ThumbnailSize.Size420x420
for i, v in pairs(PlayersFriends) do
print("Username = " .. v.Username .. " | UserId = " .. v.Id)
local clonedProfilePicture = sideMenuBackground:FindFirstChild(v.Username)
if not clonedProfilePicture then
local success, content = pcall(function()
return game.Players:GetUserThumbnailAsync(v.Id, thumbType, thumbSize)
end)
local profilePicture = player.PlayerGui.MainMenu.SideMenu.Background.ProfilePicture:Clone()
profilePicture.Name = v.Username
profilePicture.Image = success and content or "" -- Use a fallback image if retrieval failed
profilePicture.Parent = sideMenuBackground
-- Use UIListLayout or UIPageLayout for positioning the profile pictures
local layout = sideMenuBackground:FindFirstChildOfClass("UIListLayout") or sideMenuBackground:FindFirstChildOfClass("UIPageLayout")
if layout then
profilePicture.LayoutOrder = i
else
profilePicture.Position = UDim2.new(0, 10, 0, (i * profilePicture.Size.Y.Offset) + (i * 5))
end
end
end
Thank you for the recourse however this is not quite what I am looking for I am not checking to see if a players friend has player before or not; I am grabbing the players friends list and grabbing their user id’s to see the profile pictures on the gui bar, and it works in the output I get all the local players friends id’s, but they don’t update into the imagelabel shown in the screenshot. I hope this explains it a little better or if I am missing something in the recourse you provided
If it pulls up the friend, then idk why it’s only getting the local player.
EDIT: Also are you sure that you don’t have another pairs loop above with the defined variable “v”? That might be what’s happening if your getting the local player like that.
Currently Roblox does not seem to be working so ill try the link later but yes when I print the v.Id it prints the players name and id so that is working Ill have to look into it further because there are also no other for i, v loops above this or in any other script in the game sense it is new
Okay so to get the local plrs Id I made a remote event to send the local plrs Id to the server so you can put it into the friends id allowing it to go through your friends list and getting all there player id’s
Here is the client script to send the info to the server
– Retrieve the local player
local remoteEvent = game.ReplicatedStorage.PlayersFriends
local player = game.Players.LocalPlayer
local plrId = player.UserId
local thumbType = Enum.ThumbnailType.AvatarBust
local thumbSize = Enum.ThumbnailSize.Size420x420
local content = game.Players:GetUserThumbnailAsync(plrId, thumbType, thumbSize)