How would I change an ImageLabel for everyone that's playing?

As I have an icon system I’m working on, I’d like it to show an icon next to their username, however, currently the script that I have right now only works locally, and it gives everyone an icon if someone chooses a team. I’d like to know how I may go about changing my script so that everyone sees the icon

Serverscript

local function onPlayerAdded(player)
	
	for _, player in pairs(Players:GetPlayers()) do
		local Playerlist = player.PlayerGui.Playerlist
		local Template = Playerlist.Frame.Handler.Template
		local Icon = Template.Icon
			if Icon.Image then
				Icon.Image = Icon.Image
				
				
				
			end
			
		end
			
			
	end
	iconEvent:FireAllClients(onPlayerAdded)
	print("test")
	

Localscript

localPlayer:GetPropertyChangedSignal("Team"):Connect(function()
	local function localIconChange()
	for i, value in pairs(TeamArray) do
		if localPlayer.TeamColor == TeamArray[1] then
		elseif localPlayer.TeamColor == TeamArray[2] then
			Icon.Active = true
			Icon.Image = iconImageArray[2]
		elseif localPlayer.TeamColor == TeamArray[3] then
			Icon.Active = true
			Icon.Image = iconImageArray[3]
		elseif localPlayer.TeamColor == TeamArray[4] then
			Icon.Active = true
			Icon.Image = iconImageArray[4]
		elseif localPlayer.TeamColor == TeamArray[5] then
			Icon.Active = true
			Icon.Image = iconImageArray[5]
		end
		iconEvent.OnClientEvent:Connect(localIconChange)
	end
	
	refresh()
	end
end)




Players.PlayerAdded:Connect(function(newPlayer)
	refresh()
	newPlayer:GetPropertyChangedSignal("Team"):Connect(function()
		refresh()
	end)
end)

refresh()
localPlayer:GetPropertyChangedSignal("Team"):Connect(function()
	refresh()
end)

3 Likes

You could use a Remote Event and then do your changes there, so its on the server.