How to detect how many players are on a team?

How would i detect how many players are on a team and deny the player if there are 4 players on a team? (sorry if this sounds confusing

local lighting = game.Lighting

game.ReplicatedStorage.LoaderBlur:Clone().Parent = lighting

local team = script.Parent.Team

local frame = script.Parent.Parent

local player = game.Players.LocalPlayer

local playersService = game:GetService("Players")

local StarterGui = game:GetService("StarterGui")

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


script.Parent.Parent:TweenPosition(,0, 378), "Out", "Quint",1,true)

player.Team = game.Teams.Arsenal


StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)


Maybe create a value that adds one when a player joins the team

local childs = Team:GetChildren()
playesonteam= #childs
Team = game.Teams.Arsenal:GetChildren()
playesonteam= #Team 

playesonteam it will give number of players on that team

1 Like
local Team = game.Teams.Team:GetPlayers()


Using the :GetPlayers() function allows you to get a table of players on that team. #Team
is the anmount of people in that team.

1 Like

thanks! would you know how to force a player to be on a team when they join?

plr.Team = Team yo want

Use the AutoAssignable property of the team.

local teamService = game:GetService("Teams")
local team = teamService.RedTeam
local teamPlayers = team:GetPlayers()
local numberOfPlayersInTeam = #teamPlayers