My TV that shows each team with player count is not working

  1. What do you want to achieve? I want make TV that shows each team with player count
    Like this:

  2. What is the issue? Script is not even reacting to PlayerAdded function and there are no errors

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? No

Script:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		Refresh()
	end)
	player:GetPropertyChangedSignal("Team"):Connect(function()
		Refresh()
	end)
end)
function Refresh()
	for i,frame in pairs(script.Parent.Frame) do
		if frame:IsA("Frame") then
			frame:Destroy()
		end
	end
	for i,team in pairs(game.Teams) do
		if team:IsA("Team") then
			local teamDisplay = script.Template:Clone()
			local teamNameDisplay = teamDisplay:FindFirstChild("TeamName")
			local teamCountDisplay = teamDisplay:FindFirstChild("Count")
			teamCountDisplay.Text = tostring(GetCountPlayersInTeam(team))
			teamNameDisplay.Text = team.Name
			teamNameDisplay.TextColor = BrickColor.new(team.TeamColor)
			teamDisplay.Parent = script.Parent.Frame
		end
	end
end
function GetCountPlayersInTeam(team)
	local count = 0
	for i,_ in pairs(game.Players) do
		if _:IsA("Player") then
			if _.Team == team then
				count = count + 1
			end
		end
	end
	return count
end

image_2021-09-27_172314

1 Like

Surely doesn’t the function have to be above the game.Players.PlayerAdded

– Put function above it –

1 Like

Is it a value? If so remember to put _.Team.Value

Worked, but when i tested it does not show anything, it should display teams with team player count

No, you dont need put .Value, it is needed only for e.x StringValue Instance

not sure since I added print(player.Team) in each respective connections and it did print the team name.

Now when i try check if function Refresh is working and i added print, but when i tested, then it does not print anything

right, try this

for i,frame in pairs(script.Parent.Frame:GetChildren()) do

Changed some things and its working!

For everyone who want code here it is:

function Refresh()
	for i,frame in pairs(script.Parent.Frame:GetChildren()) do
		if frame:IsA("Frame") then
			frame:Destroy()
		end
	end
	for i,team in pairs(game:GetService("Teams"):GetChildren()) do
		if team:IsA("Team") then
			local teamDisplay = script.Template:Clone()
			local teamNameDisplay = teamDisplay:FindFirstChild("TeamName")
			local teamCountDisplay = teamDisplay:FindFirstChild("Count")
			teamCountDisplay.Text = tostring(GetCountPlayersInTeam(team))
			teamNameDisplay.Text = string.upper(team.Name)
			teamNameDisplay.TextColor = team.TeamColor
			teamDisplay.Parent = script.Parent.Frame
		end
	end
end
function GetCountPlayersInTeam(team)
	local count = 0
	for i,_ in pairs(game:GetService("Players"):GetChildren()) do
		if _:IsA("Player") then
			if _.Team == team then
				count = count + 1
			end
		end
	end
	return count
end
game.Players.PlayerAdded:Connect(function(player)
    Refresh()
	player:GetPropertyChangedSignal("Team"):Connect(function()
		Refresh()
	end)
end)
game.Players.PlayerRemoving:Connect(function(player)
	Refresh()
end)

EDIT: Added some things like refreshing tv on player leave

1 Like