Make it 1 player max in a team?

How would i make it one player per team?

tm = script.Parent

function onTouched(hit)

local h = hit.Parent:FindFirstChild("Humanoid")

if h ~= nil then

local n = hit.Parent

local p = game.Players:FindFirstChild(""..n.Name.."")

if p ~= nil then

p.TeamColor = tm.BrickColor

n.Humanoid.Health = 0

end

end

end

script.Parent.Touched:connect(onTouched)

local plrs = {}

local team = game:GetService("Teams"):WaitForChild("YourTeam",3)

You could do:

if #Team:GetPlayers() > 1 then
   -- error message
end
2 Likes

im sorry but how would i put this in my script?

1 Like

Actually when re-reading your script, your “Team” variable is set to nil.
You need to define the team, then it will work.

1 Like

oh thats the wrong script, give me a sec

1 Like
local teams = game:GetService("Teams")
local teamList = teams:GetTeams()
local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	for i, v in pairs(teamList) do
		if #v:GetPlayers() == 0 then
			player.Team = v
		end
	end
end)

Make sure the teams have auto-assign disabled.

1 Like