How would I create team icon system, so that each player of a specific team gets the team icon?

I’ve been trying to figure a system like this out, however, over the course of the endless hours I’ve embarked on it, I am out of ideas. I am simply looking for ideas to make this happen, as I’ve come up empty handed…
Below you’ll find my most recent effort to make it work.
Serverscript

local replicatedStorage = game:GetService("ReplicatedStorage")
local iconEvent = replicatedStorage.IconChangeEvent
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	local playerlist = player.PlayerGui:WaitForChild("Playerlist")
	local Handler = playerlist.Frame.Handler
	local Icon = Handler.Template.Icon
	player:GetPropertyChangedSignal("Team"):Connect(function(): ()
	local playerTeam = player.Team
	if playerTeam.TeamColor == BrickColor.new("Royal purple") then
		Icon.Active = true
		Icon.Image = "rbxassetid://18413761813"
	elseif playerTeam.TeamColor == BrickColor.new("Bright red") then
			Icon.Active = true
			Icon.Image = "rbxassetid://18413212927"
	elseif playerTeam.TeamColor == BrickColor.new("Dark green") then
			Icon.Active = true
			Icon.Image = "rbxassetid://18413991987"
	elseif playerTeam.TeamColor == BrickColor.new("White") then
			Icon.Active = true
			Icon.Image = "rbxassetid://18414227286"
	elseif playerTeam.TeamColor == BrickColor.new("Electric blue") then
			Icon.Active = true
			Icon.Image = "rbxassetid://18414094164"
	else
			
	end 
		iconEvent:FireAllClients(playerTeam.TeamColor, Icon.Image)
	end)
	

end)

Pertinent localscript

	if var1 == localPlayer.Team.TeamColor then
		Icon.Image = var2
	end
end)
refresh()

The current problem this system is facing is the lack of icons showing up globally, as well as the icons not matching up with the team they’re on
95a09178933e4157bee03dbb5faa6b48da5969e3

1 Like

You can do everything client-side, just make sure the players are assigned to different teams server-side.

Here’s a pseudo-code of how i’d do it:

-- Every single client will start the game and automatically assign the team for each player
-- what you want is to make each player assign the guis locally for the other players
-- and naturally the other players will do the same, because same code, same localscript that is shared

local Icons = {
       Team1 = "rbxassetid://"
}

local function AssignIcon(playerName, team)
       local UserIcon = PlayerListGui[playerName]
       UserIcon.Image = Icons[team.Name]
end

for _, player in Players:GetPlayers() do
      AssignIcon(player.Name, player.Team)
end

Players.PlayerAdded:Connect(function(player)
      AssignIcon(player.Name, player.Team)
end)

-- player.Changed:Connect(function()
        -- if a player switches team
        -- assign again new team
        -- AssignTeam(player.Name, player.Team)
--end)

Players.PlayerRemoving:Connect(function(player)
     PlayerListGui[player.Name]:Destroy()
end)
1 Like