function assignScientists(amount) local valid_players = {} local player = game.Players:GetChildren() if(#player>0)then for p = 1, #player do if(player[p].TeamColor==Americans_team.TeamColor)and (player[p].Character~=nil)then table.insert(valid_players,player[p]) end end end if(#valid_players>amount)then while(amount>0)do local rand = math.random(1,#valid_players) local chosen = valid_players[rand] chosen.TeamColor = Europeans_team.TeamColor chosen.Character.Humanoid.Health = 0 table.remove(valid_players,rand) amount = amount -1 end end end assignScientists()
In the output value, it kept saying "attempt to compare number with a nil" at line 13. I put a 0 there but yet it still says the same thing. Can anyone help me? Thank you for reading.
function assignScientists(amount) -- This function is looking for a parameter local valid_players = {} local player = game.Players:GetChildren() if(#player>0)then for p = 1, #player do if(player[p].TeamColor==Americans_team.TeamColor)and (player[p].Character~=nil)then table.insert(valid_players,player[p]) end end end if(#valid_players>amount)then while(amount>0)do local rand = math.random(1,#valid_players) local chosen = valid_players[rand] chosen.TeamColor = Europeans_team.TeamColor chosen.Character.Humanoid.Health = 0 table.remove(valid_players,rand) amount = amount -1 end end end assignScientists() --You have no parameters
Try adding a parameter to assignScientists()
at the bottom. This may fix the issue with amount
being nil.
Example: assignScientists(0)
function playScientists() if countPlayers()<=3 then assignScientists(1)
Well, I added another code that was like this but it didn't work.