Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is it possible to get the number of player on a team?

Asked by 9 years ago

I'm trying to make a script where when you click a GUI button it spawns you on the team with less players. I though about creating two IntValues for each team but again I don't know how you would get a value with that. Could you use :GetChildren with the team name and if you can how do you convert that to a number?

0
Have you looked at the AutoAssignable property of a team? GoldenPhysics 474 — 9y

1 answer

Log in to vote
0
Answered by
Kratos232 105
9 years ago

You could make a function, that gets how many Players have a certain TeamColor (the team you're counting's) e.g-

function GetMembersOnTeam(Color) -- Function
local Count = 0 -- Starts at 0.

for i, v in pairs(Game.Players:GetPlayers()) do -- Looks through all the Players
if tostring(v.TeamColor) == Color or v.TeamColor == Color then -- Checks Players' Team Colors.
Count = Count + 1 -- Increases value of Count
end
end

return Count
end

then in the Button, something like this-

Teams = Game:GetService("Teams")
Player = script.Parent.Parent.Parent.Parent -- Keep adding ".Parent" until you reach the Player

--// Change these to their names.
Team1 = Teams["Team1Name"]
Team2 = Teams["Team2Name"]


function GetMembersOnTeam(Color)
-- Rest of the function goes here...
end


script.Parent.MouseButton1Click:connect(function()

-- Gets number of TeamMembers
local count1 = GetMembersOnTeam(Team1.TeamColor)
local count2 = GetMembersOnTeam(Team2.TeamColor)

--// If there's more members on one team, then it places the player in the other team. If team numbers are equal, forces the Player into Team1
if count2 > count1 then
Player.TeamColor = Team2.TeamColor
else
Player.TeamColor = Team1.TeamColor
end

-- Respawns character
Player:LoadCharacter()

end)

That should do about what you're looking for. You'll have to change it to their actual Team's Names though.

0
okay Thanks for the help! austin10111213 28 — 9y
0
Its not working and there is no output error? austin10111213 28 — 9y
Ad

Answer this question