GetUserThumbnailAsync For every Member of a Team

Hello Roblox Community,
so my question is, how can you get alle the userprofilpictures from a team and paste them into pictures? Like this:
team
This is my script:

local img = script.Parent

local player = game.Players.LocalPlayer

local userId = player.UserId

local thumbType = Enum.ThumbnailType.AvatarBust

local thumbSize = Enum.ThumbnailSize.Size420x420

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

img.Image = content

img.Text = player.Name

Thanks to everyone who helps me,
~ Maini

Try this:

--//Services
local Players = game:GetService("Players")

--//Variables
local LocalPlayer = Players.LocalPlayer
local ImageHolder = script.Parent

--//Functions
local function SetImages()
	local images = {}
	
	for i, image in ipairs(ImageHolder:GetChildren()) do
		if image:IsA("ImageLabel") then
			table.insert(images, image)
		end
	end
	
	for i, image in ipairs(images) do
		local player = LocalPlayer.Team:GetPlayers()[i]
		local userId = player.UserId

		local thumbType = Enum.ThumbnailType.HeadShot

		local thumbSize = Enum.ThumbnailSize.Size420x420

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

		image.Image = content
		image.Text = player.Name
	end
end

SetImages()

LocalPlayer.Team.PlayerAdded:Connect(function()
	SetImages()
end)

LocalPlayer.Team.PlayerRemoved:Connect(function()
	SetImages()
end)

Make sure to put all your images in the script’s parent.

I mean the Player Profilpicture that you can see your roblox profil

Can you please answer?

Yes, my script does that.

He wanted the HeadShot so i changed it…

Ohh, I didn’t see that part, sorry for the misunderstanding. I changed my first script.

1 Like

Can i show the Player Profilpictures all players? Somehow?

I want that all players see which players are in the defenders team and attackers team above:
grafik

I changed the code a little bit, here is the new one:

local Enumeration = Enum
local Game = game
local Script = script
local Players = Game:GetService("Players")
local Teams = Game:GetService("Teams")

local RedTeam = Teams.Attackers
local BlueTeam = Teams.Defenders

local TeamsGui = Script:FindFirstAncestorOfClass("ScreenGui")
local RedTeamFrame = script.Parent.EnemyTab.Tabs
local BlueTeamFrame = script.Parent.AllyTab.Tabs

local TeamFrames = {[RedTeam] = RedTeamFrame, [BlueTeam] = BlueTeamFrame}

for _, Team in ipairs(Teams:GetTeams()) do
	local function OnTeamPlayerAdded(Player)
		print(TeamFrames[Player.Team])
		local TeamFrame = TeamFrames[Player.Team]
		if not TeamFrame then return end
		local PlayerImage = TeamFrames[Player.Team]:FindFirstChild(Player.Name)
		if not PlayerImage then
			local Success, Result = pcall(function() return Players:GetUserThumbnailAsync(Player.UserId, Enumeration.ThumbnailType.AvatarBust, Enumeration.ThumbnailSize.Size420x420) end)
			if not (Success and Result) then warn(Result) return end
			PlayerImage = Instance.new("ImageLabel")
			PlayerImage.Name = Player.Name
			PlayerImage.Size = UDim2.new(0.112, 0, 0.857, 0)
			PlayerImage.Image = Result
			PlayerImage.Parent = TeamFrames[Player.Team]
			PlayerUICorner = game.ReplicatedStorage.UI.UICorner:Clone()
			PlayerUICorner.Parent = PlayerImage
			
		end
		PlayerImage.BackgroundColor3 = Player.TeamColor.Color
	end
	
	local function OnTeamPlayerRemoved(Player)
		local TeamFrame = TeamFrames[Team]
		if not TeamFrame then return end
		local PlayerImage = TeamFrame:FindFirstChild(Player.Name)
		if PlayerImage then PlayerImage:Destroy() end
	end
	
	Team.PlayerAdded:Connect(OnTeamPlayerAdded)
	Team.PlayerRemoved:Connect(OnTeamPlayerRemoved)
	for _, Player in ipairs(Team:GetPlayers()) do
		OnTeamPlayerAdded(Player)
	end
end

Thanks
~Maini