Team Player Icon List

  1. What do you want to achieve?

Currently atm I am building a 5v5 game, and I was wondering how I can put the players icons/thumbnails on an image template and display each for each team.

Just like this →

  1. What is the issue?

I already have everything set up. I know how to display the images, get the players icon, etc. I just don’t know how to get all of the players on the team and display all of them. I also wanted to add a way to put a death/dead symbol (x) on them when they die.

  1. What solutions have you tried so far?

I have tried many ways. I am wondering how I can do this through the local side? I am sure I probably need to do this through my ServerScript though. Could this be done using my previous post?

function update(player)
	for i,v in pairs(Teams:GetDecsendants()) do
		local new = Template:Clone()
		-- I would need to get the players team.
        -- then place that image on the template. 
	end
end

I already know the easy stuff - >

local UserId = player.UserId
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local content, isReady = Players:GetUserThumbnailAsync(UserId, thumbType, thumbSize)

This is being used for the main menu.

Also part of my team manager system →

-- script
game.ReplicatedStorage.TeamChange.OnServerInvoke = function(plr, teamName)
	local team = game.Teams:FindFirstChild(teamName)
	if team and team:FindFirstChild("MaxPlayers") then
		if team.MaxPlayers.Value > #team:GetPlayers() then
			plr.Team = team
			plr:LoadCharacter()
			return true
		else
			return false
		end
	end
end
-- local script
local success = game.ReplicatedStorage.TeamChange:InvokeServer(button.Name)
			if success ~= true then
				GUI.TeamChooser.Error.Visible = true
				wait(1)
				GUI.TeamChooser.Error.Visible = false
				GUI.TeamChooser.Visible = true
			elseif success == true then
				GUI.TeamChooser.Visible = false
				GUI.ScoreBoard.Visible = true
				--update(player.Team)
			end

Could I use the Serverscript Manager as a way to implement this?

You could probably make a remote event for this, and FireAllClients()

1 Like
local BlueIconTable = {}
local RedIconTable = {}

for _, Player in ipairs(game:GetService("Players"):GetChildren()) do
local Content, Ready = game:GetService("Players"):GetUserThumbnailAsync(userId, thumbType, thumbSize)
 
if Player.Team.Name == "Blue" then
table.insert(BlueIconTable, Content)
elseif Player.Team.Name == "Red" then
table.insert(RedIconTable, Content)
end
end

then loop through the tables like so

for _, Icon in ipairs(BlueIconTable) do
local Label = Instance.new("ImageLabel")
Label.Image = Icon
Label.Parent = -- PATH TO YOUR BLUE TEAM ICON GUI
end

for _, Icon in ipairs(RedIconTable) do
local Label = Instance.new("ImageLabel")
Label.Image = Icon
Label.Parent = -- PATH TO YOUR RED TEAM ICON GUI
end

this was written on mobile too so there might be some errors

you should have a template preset in replicatedstorage or wherever you usually store stuff with the death icon already on it (but invisible) which you can clone instead of creating a new imagelabel

name the imagelabels the users usernames

when someone dies (check that on the server) fireallclients on a death remote passing the dead players name thru it and on then on the client you receive their name and do findfirstchild(deadname) and then change the visibility of the skull icon inside of the imagelabel

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

local RedTeam = Teams.RedTeam
local BlueTeam = Teams.BlueTeam

local TeamsGui = Script:FindFirstAncestorOfClass("ScreenGui")
local RedTeamFrame = TeamsGui:FindFirstChild("RedTeamFrame")
local BlueTeamFrame = TeamsGui:FindFirstChild("BlueTeamFrame")

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.AvatarThumbnail, 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, 420, 1, 0)
			PlayerImage.Image = Result
			PlayerImage.Parent = TeamFrames[Player.Team]
		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

Here’s an implementation I wrote which should achieve what you’re looking for, everything is handled on the client as there is no need for server dependency.

Here’s the place file so you can carry out your own preliminary tests.
Gui.rbxl (30.8 KB)

It listens for the PlayerAdded and PlayerRemoving signals of each team, if a team receives a player, that player’s icon is added to that team’s frame, if a team loses a player, that player’s icon is removed from that team’s frame. This has also been made in a way such that it populates icons for existing players and correctly removes a player’s icon if that player leaves the game.

2 Likes

Why do you put these 3 variables, they are useless and just take extra time to type

This is a very late response but he used those for micro-optimizations. Global variables take longer to access than local variables.
He references the global variables as local so it’s faster for the script to access.

3 Likes

No problem, glad I at least know now.