01 | function assignScientists(amount) |
02 | local valid_players = { } |
03 | local player = game.Players:GetChildren() |
04 | if (#player> 0 ) then |
05 | for p = 1 , #player do |
06 | if (player [ p ] .TeamColor = = Americans_team.TeamColor) and |
07 | (player [ p ] .Character~ = nil ) then |
08 | table.insert(valid_players,player [ p ] ) |
09 | end |
10 | end |
11 | end |
12 | if (#valid_players>amount) then |
13 | while (amount> 0 ) do |
14 | local rand = math.random( 1 ,#valid_players) |
15 | local chosen = valid_players [ rand ] |
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.
01 | function assignScientists(amount) -- This function is looking for a parameter |
02 | local valid_players = { } |
03 | local player = game.Players:GetChildren() |
04 | if (#player> 0 ) then |
05 | for p = 1 , #player do |
06 | if (player [ p ] .TeamColor = = Americans_team.TeamColor) and |
07 | (player [ p ] .Character~ = nil ) then |
08 | table.insert(valid_players,player [ p ] ) |
09 | end |
10 | end |
11 | end |
12 | if (#valid_players>amount) then |
13 | while (amount> 0 ) do |
14 | local rand = math.random( 1 ,#valid_players) |
15 | local chosen = valid_players [ rand ] |
Try adding a parameter to assignScientists()
at the bottom. This may fix the issue with amount
being nil.
Example: assignScientists(0)
1 | function playScientists() |
2 | if countPlayers()< = 3 then |
3 | assignScientists( 1 ) |
Well, I added another code that was like this but it didn't work.