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

I keep getting an Interval is empty error?

Asked by 6 years ago

So this code seems to work just fine running it in Studio, But when I test it on the Client and Servers option it give me the error:

ServerScriptService.PlayerChooser:20: bad argument #2 to 'random' (interval is empty)

local vPlayers = game.Players.NumPlayers
local vPlayer = game.Players.LocalPlayer

    while wait(1) do
vPlayerAmount = {}

for _, vPlayer in pairs(game.Players:GetPlayers()) do

    if vPlayer and vPlayer.Character then
local vHumanoid = vPlayer.Character:WaitForChild("Humanoid")

    if vHumanoid and vHumanoid.Health > 0 then
        table.insert(vPlayerAmount, vPlayer)

        end
    end
end 
    if #vPlayerAmount <= 2 then

     vSimonP = vPlayerAmount[math.random(1, #vPlayerAmount)]

    if vSimonP then
    vSimonP.Team = game.Teams.Simon

            end
        end     
    end

I'm guessing it has to do with the table but i'm not sure what I should fix! Any help is appreciated!

0
That error can occur when the 2nd argument(maximum number) is more than the 1st argument(minimum number) Rare_tendo 3000 — 6y
0
So you're saying I should switch the vPlayerAmount and the 1? OpticalAce 49 — 6y
0
You are trying to do math.random(1,0) which is giving you the error. You can test it out with `print(math.random(1,0)` and it will give you the same error. MooMooThalahlah 421 — 6y

Answer this question