Attempt to index nil with ‘Name’

I’m currently in the process of using an array for the first time, however, as I’m using it, it gets to a certain point and then spits out this error. I’ve tried reorganizing the teams a little, but that seemingly didn’t work out. It is also my first time messing around with pairs.

The localscript responsible

local teamTable = {
	["Lime green"] = "rbxassetid://18413212927",
	["Dark blue"] = "rbxassetid://18414094164",
	["Maroon"] = "rbxassetid://18414227286"
}


StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)

for i, team in pairs(Teams:GetChildren()) do
	_teams [team.Name] = i
end

for i, value in pairs(teamTable) do
	if localPlayer:GetPropertyChangedSignal("Team") then
		if localPlayer.Team.Name == i then
			Icon.Image = value
			Icon.Active = true
			
		end
	end
end

Try if localPlayer.TeamColor == 1 then

it doesn’t throw the error anymore, but I’m still facing another bug. Upon team switch, it doesn’t show the icon. In fact, it remains inactive within the playergui…

“if the Player isn’t on a team or has an invalid Player.TeamColor, this property is nil.”

Make sure player is assigned to a team.

You have to listen to whenever team is changed on client-side.

localPlayer:GetPropertyChangedSignal("Team"):Connect(function()
--update
end)

would this suffice?

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

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

ah I forgot to include my function. my bad

local function refresh()
	for _, obj in pairs(Frame:GetChildren()) do
		if obj:IsA("TextLabel") then
			obj:Destroy()
		if obj:IsA("ImageLabel") then
			obj:Destroy()
		end
	end
end
for _, player in pairs(Players:GetPlayers()) do
		local Text = Template:Clone()
		Text.Parent = Frame
		Text.Text = player.Name	
		if player.Team then
			Text.TextColor3 = player.TeamColor.Color
			Text.LayoutOrder = _teams[player.Team.Name]
		else
			Text.LayoutOrder = #Teams:GetChildren() + 1

		end
	end
end

That PlayerAdded doesn’t fire for you since your LocalScripts are executed once you join.
But yes, the rest is fine, you can just pass the function in Connect instead of creating anonymous function that calls the refresh function

curiously enough, when I try to print the value after I connect a refresh function, the value doesn’t print… I’m unsure as to why this is

image

First of all, you don’t need to connect to the event for each iteration

That’s all you needed