Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

1 comment

0

Is that your entire script?

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.