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

Script only puts 2 players in?

Asked by 9 years ago

Hi guys! This script picks two players and puts them in the blue team, then the rest should go in the green team. However, the two players go in the blue team but only two players go in the green team. Even if there are 8 people in the server only the 4 go in the teams ;( It is so weird?! Any ideas? Thanks

id = 186964027
list = {}
function AddPlayers()
for i,v in pairs (game.Players:GetPlayers()) do
    table.insert(list,v)
if game:GetService("GamePassService"):PlayerHasPass(v,id) then
table.insert(list,v)
end
end
num1 = math.random(1,#list) --Number
num1 = list[num1] -- Value from the table
num1.TeamColor = BrickColor.Blue() 
num2 = math.random(1,#list) --Number
num2 = list[num2] -- Value from the table
num2.TeamColor = BrickColor.Blue()
print(num1)
print(num2)
if num2.Name == num1.Name then
 repeat
  num2 = math.random(1,#list)
  num2 = list[num2]
  num2.TeamColor = BrickColor.Blue()
 until
 num2.Name ~= num1.Name
end
for i,v in pairs (list) do
if v.Name ~= num1.Name and v.Name ~= num2.Name then
v.TeamColor = BrickColor.new("Bright green")
for i = 1, #list do
table.remove(list, i)
end
wait(5)
end
end
end

1 answer

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
9 years ago

I believe it is a problem with you final generic for loop. Inside of it you nested another for loop that clears the list.

What you want to do is search through the list changing all the other unselected player's TeamColor to Bright green and then clear the list.

for i, v in ipairs (list) do
    if v.Name ~= num1.Name and v.Name ~= num2.Name then
        v.TeamColor = BrickColor.new("Bright green")
    end
end
list = {}
Ad

Answer this question