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

invalid argument #2 to 'random' (interval is empty)?

Asked by 2 years ago

I was trying to make a bomb tag game, so I tried to make a random player start with the bomb. But for some reason, I get an error.

local Players = game:GetService("Players"):GetChildren()
local Randomplayer = Players[math.random(1, #Players)]

print(Randomplayer)

EquipBomb:FireClient(Randomplayer, Bomb)

I have no idea what to do, I've looked at many websites and none have helped.

0
Is that your entire script? COUNTYL1MITS 312 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

Invalid argument #2 to random is basically an error when the 2nd argument of math.random is less than the 1st argument. Try to add a wait() before the random player thing executes since once you press the play button the script just starts running before the player fully loads in and so #game.Players:GetChildren() is still 0.

wait(4)
local players = game.Players:GetChildren()
local random = players[math.random(1,#players)]
print(random)
Ad

Answer this question