Team Counting Players Script Won't Work for a mysterious reason?

Hello everyone! I have a sort of mini game system that puts players on a playing team if they’re playing and a lobby team if they aren’t.

I have come across a peculiar issue where I am using a while loop with an if statement inside to check if the amount of players inside of a team is equal to 1. However, when I am printing the amount of players on a team, it stays at 0. The script cannot count the amount of players on a team and constantly check for my if statement to work.

I have tried using the GetPropertySignal function to also check if the team amount of players has changed for my if statement to check if 1 player is left on a team works, but that still doesn’t work and even shows no error. Strange.

Here is my code right now:

while true do
wait(1)
local teamPlayers = game:GetService("Teams")["Playing"]:GetPlayers()

		print(#teamPlayers .. " are still playing... CHECKED")

		if #teamPlayers == 1 then
			--stuff
		end
end

Any help is heavily appreciated… thanks!

Have you already assigned the players Player.Team to the Playing team?

Additionally, you can detect players that join and leave the team for example:

local teams = game:GetService("Teams")

game.Players.PlayerAdded:Connect(function(plr)
	wait(2)
	
	plr.Team = teams.Red
end)

teams.Red.PlayerAdded:Connect(function(plr)
	print(plr.Name .. " was added to team Red!")

	if #(teams.Red:GetPlayers()) == 1 then
		print("We only have 1 player in team red!")
	end
end)

teams.Red.PlayerRemoved:Connect(function(plr)
	print(plr.Name .. " was removed from team Red!")
	
	if #(teams.Red:GetPlayers()) == 1 then
		print("We only have 1 player in team red!")
	end
end)

by the way make sure your teams color isn’t white because for some reason Roblox auto assigns players to teams that are color white.

1 Like

My team color was white, and that seemed to be the issue. Thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.