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.MouseButton1Click:Connect(function()

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

player.Team = game.Teams.Arsenal

game.Lighting.LoaderBlur:Destroy()

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

end)

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

https://developer.roblox.com/en-us/api-reference/function/Instance/GetChildren

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()

print(#Team)

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?

game.Players.PlayerAdded:Cconnect(Function(plr)
plr.Team = Team yo want
end)

Use the AutoAssignable property of the team.

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