Okay, one part of a new game I'm making is a simulated "Stock Market"... The player buys a "stock" at a certain price, and can sell it at either a loss or gain after the script refreshes its value after x amount of time... The amount of times it will loop successfully has varied for me, anywhere from once to 5 times, all of it eventually giving me the same error.
KNG = 250
OCT = 1500
SHL = 2000
SNY = 4350
DEL = 8750
MCR = 25000
a = 0
--Prints new values to console
function updateConsole()
print("KNG - ", KNG, "OCT - ", OCT, "SHL - ", SHL, "SNY - ", SNY, "DEL - ", DEL, "MCR - ", MCR)
end
--Updates values for each stock
function newValue(stock)
stock = stock + math.random(-(1.5*stock), (1.5*stock))
if stock < 0 then
stock = math.random(-2500, 100) --Keep stock from falling too hard...
end
return stock
end
updateConsole() --Prints out initial values (Debug & Pre-GUI)
--Loops new updates 100 times.
while a <= 100 do
wait(5)
KNG = newValue(KNG)
OCT = newValue(OCT)
SHL = newValue(SHL)
SNY = newValue(SNY)
DEL = newValue(DEL)
MCR = newValue(MCR)
updateConsole()
a = a + 1
end
KNG - 250 OCT - 1500 SHL - 2000 SNY - 4350 DEL - 8750 MCR - 25000 KNG - 179 OCT - 508 SHL - 2413 SNY - 6728 DEL - 15466 MCR - 41644 KNG - 430 OCT - 787 SHL - -219 SNY - 13221 DEL - 19273 MCR - 3084 21:40:50.373 - Workspace.Stock Values:16: bad argument #2 to 'random' (interval is empty) 21:40:50.375 - Stack Begin 21:40:50.376 - Script 'Workspace.Stock Values', Line 16 - global newValue 21:40:50.377 - Script 'Workspace.Stock Values', Line 29 21:40:50.378 - Stack End
KNG - 250 OCT - 1500 SHL - 2000 SNY - 4350 DEL - 8750 MCR - 25000 KNG - 134 OCT - 1373 SHL - 1250 SNY - 8878 DEL - 3943 MCR - 21707 KNG - 124 OCT - -1190 SHL - 2120 SNY - 6363 DEL - 1336 MCR - 26184 22:06:51.928 - Workspace.Stock Values:16: bad argument #2 to 'random' (interval is empty) 22:06:51.930 - Stack Begin 22:06:51.932 - Script 'Workspace.Stock Values', Line 16 - global newValue 22:06:51.934 - Script 'Workspace.Stock Values', Line 28 22:06:51.935 - Stack End
I tried running it without lines 17-19 and it did effect the problem at all, other than made it 3 lines shorter for the same error. I also tried changing the stock = stock + math.random(-(1.5*stock), (1.5*stock)) to stock = stock + math.random((-1.5*stock), (1.5*stock)) and got the same result.
Eventually I'm going to make it run as a table, but I'm just getting back into LUA from vb.net and C++, and tables and arrays work differently in LUA, and as I get further in the dev. cycle, this script will definitely be expanded on, this was just a quick little thing I put together trying to see how branching off from this would work. Any help is greatly appreciated!

3 comments
Make sure all the math.random() things are arranged in ascending order, on whichever line fires "Interval is empty". They should be formatted as: math.random(lower, higher)
It's because math.random takes integers, not floats. I recommend using the math.floor() and math.ceil() functions to round down or up the float values.
"interval is empty" means that the first value is greater than the second value. The data type of the numbers does not matter for this error, like SquirrelOnToast said.