Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make Team have limited number of players?

How do i make team limit like i want to have 2 people in team medic and other didnt limit how do i make it?

1 comment

0

You need to learn how to do it first. Scriptinghelpers is here to HELP you, not make a script for you.

2 answers

This script gets the number of players in a team and returns how many count is.

function GetPlayersOnTeam(team)
local count=0;
for i,v in next,Game.Players:GetPlayers() do
if v.TeamColor==team then
count=count+1
end
end
return count;
end

local team1=BrickColor.new("Blue") -- Change this to your team
local teams=10

Game.Players.PlayerAdded:connect(function(player)
if GetPlayersOnTeam(team1)< teams then
player.TeamColor=team1
else player.TeamColor= Red -- Change this to your team name
end
end)

To make a team limit, you will need to make the teams using a script, rather than using the team object. I have made a simple script that is easy for you to understand. (Please take note that this is a site for people who have errors in there lua code, not a script requesting site)

local max = 15 --The Player Team Limit for both teams
local Team1 = "TEAM NAME" --Enter team 1
local Team2 = "TEAM NAME"  -Enter team 2

function checkTeams(plr)
	repeat wait() until plr.Character
	
	local Team1 = {}
	local Team2 = {}
	
	if plr.Team == game.Teams[Team1] then
		for i, v in pairs(game.Players:GetPlayers()) do
			if v and v.Team == game.Teams[Team1] then
				table.insert(Team1, v)
			end
		end
		
		if #Team1 > max then
			plr:Kick("Team Limit Reached")
		end
		
	elseif plr.Team == game.Teams[Team2] then
		for a, b in pairs(game.Players:GetPlayers()) do
			if b and b.Team == game.Teams[Team2] then
				table.insert(Team2, b)
			end
		end
		
		if #Team2 > max then
			plr:Kick("Team Limit Reached")
		end
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	checkTeams(plr)
end)

game.Teams[Team1].PlayerAdded:Connect(function(plr)
	checkTeams(plr)
end)

game.Teams[Team2].PlayerAdded:Connect(function(plr)
	checkTeams(plr)
end)

1 comment

0

Why are you kicking the player? Are you retarded?

This discussion is preserved as it was. New answers, comments, and votes are closed.