Help in making a player list system

Hello fellow developers ! I am trying to create a player list system for my game which will show the pictures of all the 8 players in the lobby and is mostly like that of arsenal. I have created a screen GUI and used UIgridlayout and used 8 frames. I will be using this code to get the player image.

local Players = game:GetService("Players")
 
local player = Players.LocalPlayer
 
-- Fetch the thumbnail
local userId = player.UserId
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
 
-- Set the ImageLabel's content to the user thumbnail
local imageLabel = script.Parent
imageLabel.Image = content
imageLabel.Size = UDim2.new(0, 420, 0, 420)

now the problem is I don’t know what type of script and where should I prepare it because the script will get different image for all the players which will be their own pic. I would really appreciate any help on fixing this and getting the pictures of all the eight players in the lobby. Thanks !

1 Like

I think you should make a local script which controlls all the activities of the player list . In that script, make a refresh function ( when something changes in the player list ,the script will refresh all player gui - clear all images and clone them again [a bit werid] but you can try another way that if somebody’s stat changes, it will only change the player’s frame )

1 Like

You can use a local script and add or remove the guis to the UIgridlayout whenever a player leaves or joins (you can use game.Players.PlayerAdded and game.Players.PlayerRemoving) to detect players leaving or joining

And game.Players.PlayerAdded and Player Removing has a parameter which gives the joining or leaving player so you can use that to get the userids and the player thumbnails

Example:

game.Players.PlayerAdded:Connect(function(player)
    -- Fetch the thumbnail
local userId = player.UserId
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
 
end)
1 Like

I wrote this code



local Players = game:GetService("Players")

local player = Players.LocalPlayer

game.Players.PlayerAdded:Connect(function(player)

-- Fetch the thumbnail

local userId = player.UserId

local thumbType = Enum.ThumbnailType.HeadShot

local thumbSize = Enum.ThumbnailSize.Size420x420

local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)

-- Set the ImageLabel's content to the user thumbnail

local imageLabel = script.Parent

imageLabel.Image = content

imageLabel.Size = UDim2.new(0, 420, 0, 420)

end)

but the image of the player is not being shown on the GUI when I launch the game for test. This is the how I have prepared the gui. Screenshot 2021-08-18 at 3.27.42 PM
is there any problem in how I have arranged it ? The 1 to 8 number frames represent 8 players and each frame should display the picture of a different player.

There are two variables named player so It may have caused a problem

Also if you put this code on every label then they will all show the latest player that joined

Instead you should have only one script and one gui, when a player joins you clone the gui and set its image id to the players thumbnail

1 Like