So this script is supposed to print "Enough players" when both teams have enough players, and say "Not enough players" when neither team has enough players. However, the script is not working, and I don't know why. Can someone please help me?
Here's the script:
local team = game.Teams; function getPlayers(teamColor) local found = { }; for _,v in pairs(game.Players:GetPlayers()) do if v.TeamColor == teamColor then table.insert(found, v) end end return #found end while wait() do getPlayers(BrickColor.new('Bright green')).Changed:connect(function() getPlayers(BrickColor.new('Bright red')).Changed:connect(function() if getPlayers(BrickColor.new('Bright green')) > 0 and getPlayers(BrickColor.new('Bright red')) > 0 then print('Enough players') elseif getPlayers(BrickColor.new('Bright green')) == 0 or getPlayers(BrickColor.new('Bright red')) == 0 then print('Not enough players') end end) end) end
You cannot use the Changed
event on a custom function, it's used for values. Read more here
local team = game.Teams; function getPlayers(teamColor) local found = { }; for _,v in pairs(game.Players:GetPlayers()) do if v.TeamColor == teamColor then table.insert(found, v) end end return #found end while wait() do local greenNum = getPlayers(BrickColor.new('Bright green')) local redNum = getPlayers(BrickColor.new('Bright red')) if greenNum > 0 and redNum > 0 then print('Enough players') else print('Not enough players') end end