Invalid argument #2 to 'random' (interval is empty)

This code works fine when the round first starts. When the round starts again, I get the error shown on the title. When I am testing it, there are no seekers and I am the only one on neutral. This is the case both on the first and next round.

seeker = game.Players:GetPlayers()[math.random(1, #game.Teams.Neutral:GetPlayers())]
#game.Teams.Neutral:GetPlayers()

That means this is 0, the 2nd argument to math.random() can’t be less than the 1st.

1 Like

instead of using hashtags
use something like this

to count items

1 Like

That’s only necessary for dictionaries, :GetPlayers() returns an array of player instances.

4 Likes

Hey so what I mean is that the variable gets a random player from the team, but then it only works the first time it does it. The second time it does not and provides an error; in both cases, the amount of players in the neutral team is the exact same, and the intermission gives sufficient time for the players to load in, which is why I am confused that the second argument is not detecting the players in the neutral team.

Edit: I fixed it myself. I changed the second argument to game:GetService(“Players”):GetPlayers(). I got this from AlvinBlox (the YouTuber). Also, I changed a variable from local to global; sorry I did not specify I did these things.

1 Like