local function getTeamPlayers(teamColor) local output = {} for _, player in pairs(game.Players:getPlayers()) do if (not player.Neutral) and player.TeamColor == BrickColor.new(teamColor) then table.insert(output, player) end end return output end print(getTeamPlayers("Bright blue")) -->the number of players on the Bright blue team function onClicked() print "test" -- To test if it even gets up to this point if (getTeamPlayers("Bright blue")) < 17 then print(getTeamPlayers("Bright blue")) game.Players.LocalPlayer.TeamColor = BrickColor.new("Bright blue") end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
The above script does not work. It is supposed to find out the number of people on one team (The top area) and when a button is pressed use the top area to find out whether it can allocate the presser to the team (hence < 17). The thing is, it outputs a table, so how can I get the output to work with the bottom?
Your code outputs a table
simply because function getTeamPlayers returns output
, a table. In order to find the number of players on the team, you would have to use the length operator, which would return an integer indicating the number of entries in the table.
#getTeamPlayers() -- would return the number of players --with on the Bright blue team.
It essentially works somewhat like this..
length = function( tab ) local count = 0 -- increases in accordance with --number of entries in provided table for index, value in next, tab do -- iterates through provided table count = count + 1 end return count -- returns total amount of found entries in table `tab` end length(getTeamPlayers())
function onClicked() print "test" -- To test if it even gets up to this point if (#getTeamPlayers("Bright blue")) < 17 then print(#getTeamPlayers("Bright blue")) game.Players.LocalPlayer.TeamColor = BrickColor.new("Bright blue") end end script.Parent.ClickDetector.MouseClick:connect(onClicked)