The image not changing on OverheadGUI

Hello, I am coding for when the team changed the icon will change too but it didn’t change.

Here is my code: (Server side)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("Team")

local NameDisplay = script:WaitForChild("NameDisplay")

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local clone = NameDisplay:Clone()
		local PlrHead = char:WaitForChild("Head")
		
		clone.Parent = PlrHead
		clone:WaitForChild("Username"):WaitForChild("UsernameLabel").Text = player.Name
		clone:WaitForChild("Username"):WaitForChild("UsernameLabel").TextColor = BrickColor.new("Deep orange")
		clone:WaitForChild("Username"):WaitForChild("ShadowLabel").Text = player.Name
		clone:WaitForChild("Team"):WaitForChild("TeamHold"):WaitForChild("TeamLabel").Text = player.Team.Name
		clone:WaitForChild("Team"):WaitForChild("TeamHold"):WaitForChild("TeamLabel").TextColor = BrickColor.new("Deep orange")
		
	end)
end)

RemoteEvent.OnServerEvent:Connect(function(Player, teamName)
	local Char = Player.Character
	local Username = Char:FindFirstChild("Head"):FindFirstChild("NameDisplay"):FindFirstChild("Username"):FindFirstChild("UsernameLabel")
	local TeamLabel = Char:FindFirstChild("Head"):FindFirstChild("NameDisplay"):FindFirstChild("Team"):FindFirstChild("TeamHold"):FindFirstChild("TeamLabel")
	local Icons = Char:FindFirstChild("Head"):FindFirstChild("NameDisplay"):FindFirstChild("Icons"):FindFirstChild("ImageLabel")

	if teamName == "Engineering Department" then
		Player.TeamColor = BrickColor.new("New Yeller")
		TeamLabel.Text = "Engineering Department"
		Username.TextColor = BrickColor.new("New Yeller")
		TeamLabel.TextColor = BrickColor.new("New Yeller")
		Icons.Image = "rbxassetid://14379366079"
		Player:LoadCharacter()
	end
end)


https://gyazo.com/a5cac62fa6d9fa91ffb8de75f0a5a317

You may see on the video that an orange icon was not change

Thanks!

hmm thats bit weird, maybe your image didn’t load or you did typo on the image id? thats all i can think about it

Let’s read over what you’re doing.

  1. On the event being fired you do the following:
  2. The player gets teamed and their icon gets set.
  3. You respawn the character, so the icon gets set to default.

You have to set the icon script inside of the CharacterAdded function to fix this.

  1. Get the player’s team.
  2. Set the icon.

To further optimise & making setting up the script easier you can do the following:

local teamIcons = { [BrickColor.new("New Yeller")] = "14379366079" }

-- Inside the function:
if teamIcons[teamColor] then
   -- set icon to teamIcons[teamColor]
end

Or you can have it as an attribute to the team.

if Team:GetAttribute("Icon") then
   -- set icon to Team:GetAttribute("Icon")
end
1 Like