Why does this code give me an error? CODE:
local Players = game.Players:GetPlayers() local Phantom = Players[math.random(1, #Players)]
Error: Workspace.Script:5: bad argument #2 to 'random' (interval is empty) Please Help, Thanks for reading.
Most likely this is because there are no players in the game. math.random
expects the first number to be lower than the second, and throws an error if it isn't true.
You're going to have to check if game.Players.NumPlayers
is > 0
before running that code:
while game.Players.NumPlayers < 1 do wait() end local Players = game.Players:GetPlayers() local Phantom = Players[math.random(#Players)] --The `1, ` is implied here.