Team Counter Surface Gui doesnt work

So I made this team counter for my game. but I want it to display on the television so I made a surface GUI and a few text labels with each team. This is the script I wrote:

local RedTeam = game.Teams.Red:GetPlayers()

local BlueTeams = game.Teams.Blue:GetPlayers()

while true do

wait(0.1)

script.Parent.RedTeam.Text = "Red " .. #RedTeam

script.Parent.BlueTeam.Text = "Blue " .. #BlueTeams

end

But it doesn’t seem to show on the Surface Thing. Here is a video:

The amount would never update, try only defining the team and not the amount of players in the team.

local RedTeam = game.Teams.Red
local BlueTeam = game.Teams.Blue

while true do

wait(0.1)

script.Parent.RedTeam.Text = "Red " .. #RedTeam:GetPlayers()

script.Parent.BlueTeam.Text = "Blue " .. #BlueTeam:GetPlayers()

end
1 Like

Using a while true do loop like that is bad practice.

local RedTeam = game.Teams.Red
local BlueTeam = game.Teams.Blue

RedTeam.PlayerAdded:Connect(function()
    script.Parent.RedTeam.Text = "Red: " .. #RedTeam:GetPlayers()
end)

BlueTeam.PlayerAdded:Connect(function()
    script.Parent.BlueTeam.Text = "Blue: " .. #BlueTeam:GetPlayers()
end)

but if the player changes his team the number of the team he was on doesn’t go down. it stays at thenumber

Apologies.

local RedTeam = game.Teams.Red
local BlueTeam = game.Teams.Blue

RedTeam.PlayerAdded:Connect(function()
    script.Parent.RedTeam.Text = "Red: " .. #RedTeam:GetPlayers()
end)

RedTeam.PlayerRemoved:Connect(function()
    script.Parent.RedTeam.Text = "Red: " .. #RedTeam:GetPlayers()
end)

BlueTeam.PlayerAdded:Connect(function()
    script.Parent.BlueTeam.Text = "Blue: " .. #BlueTeam:GetPlayers()
end)

BlueTeam.PlayerRemoved:Connect(function()
    script.Parent.BlueTeam.Text = "Blue: " .. #BlueTeam:GetPlayers()
end)

Don’t think it was.

I’m aware.

1 Like

I’m tired, so I might be wrong.
Let’s not start a argument.