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

How To Fix Error, "bad argument #2 to 'random' (interval is empty)?"

Asked by 4 years ago

I am trying to make a crate system. I have Commons, Rares, Legends, and Godly's. Everything unboxes just fine but when I try to unbox the Godly Crate This Error Shows, " . Allbad argument #2 to 'random' (interval is empty)" Crates run through the same script, so I don't get why it does this. Help if you can! Here is the part of the codes that shows the error,

local Choose = math.random(1,100);


                local ChanceTable = {};
                for Rarity,Chance in pairs(Chances) do
                    for i = 1,Chance do 
                        table.insert(ChanceTable,Rarity);
                    end
                end;

                SelectedRarity = ChanceTable[math.random(1,#ChanceTable)];
                SelectedKnife = ItemTable[SelectedRarity][math.random(1,#ItemTable[SelectedRarity])];  -- Shows the error on this line  

                ChanceTable = {};
0
That doesn't really help, all crates open but one specific one. And they are all ran through one script. ChefDevRBLX 90 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

there are two ways math.random #2 will be an error

  1. the 2nd argument is nil, that is obvious
  2. some how, you did not forsee, but when the game starts to run, the 2nd argument is less than the first argument. from your error, I can see that your table was empty {}, so the #table is 0. because 1 > 0, random failed.
Ad

Answer this question