Hello!
This is my script as of now:
local randomPlayer = game.Players:GetPlayers() [math.random(1,#game.Players:GetPlayers())] randomPlayer.TeamColor = BrickColor.new("Really blue")
However, when I run the game, an following error appears:
17:57:25.323 - Workspace.ao oni chooser:2: bad argument #2 to 'random' (interval is empty)
Can anyone please help? Thanks!
Your error happens because the second argument in
[math.random(1,#game.Players:GetPlayers())]
can equate to zero when the script runs first before any player gets in the game, making Players:GetPlayers() return a table of length zero.
You will get the same error with
math.random(1,0)
To circumvent this error, I recommend that that portion of the script to be run only when after a player is added into the player service.