So i have 6 spawns different colors its a team, is it possible only 2 players can be on the 1 team? ex, 2 players only at Team Green and so on...
thnx :D
So i have 6 spawns different colors its a team, is it possible only 2 players can be on the 1 team? ex, 2 players only at Team Green and so on...
thnx :D
local max = 2
function getAllTeams(slotsNeeded)
local teamTab = {}
for i,v in pairs(Game:GetService('Teams'):GetTeams()) do --For all of the teams, do
if getTeamCount(v.TeamColor) < max or not slotsNeeded then --If it has less than 2 members or the argument is false then
teamTab[v.TeamColor] = getTeamCount(v.TeamColor) --Add it to the table
end
end
return teamTab
end
function getRandomIndex(tab)
local num = math.random(1,#tab) --Get a random index number
local num2 = 0
for i,v in pairs(tab) do
num2 = num2 + 1 --Add one to the other number
if num2 == num then --If the index number equals the other number
return i --Here is our index
end
end
end
function getTeamCount(TeamColor)
local count = 0
for i,v in pairs(Game.Players:GetPlayers()) do
count = v.TeamColor == TeamColor and count + 1 or count --Find the number of players with the TeamColor 'TeamColor'
end
return count
end
function fixTeams()
for i,v in pairs(Game.Players:GetPlayers()) do --For all of the players
if getTeamCount(v.TeamColor) > 2 then --If their team had over 2 players
v.TeamColor = getRandomIndex(getAllTeams(true)) --Give them a random Team
end
end
end
while wait(0) do
fixTeams()
end
Untested.
Hi sir, thank you for the effort.. i will just put this at workspace? and thank you again!!
Place it in ServerScriptService.
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
Attempt some code first. Not gonna make it for you.
Please do not use Scripting Helpers as a request site. However, this time I am able to assist you. Please allow me a moment.