I have created a script which would in theory randomly generate different chests depending on the number, but my logic seems to be incorrect. The code is as follows:
while true do
print("Looped!!!!!!")
local waittime = math.random(1,5)
wait(waittime)
if math.random(1,10) == 1 or 2 or 3 or 4 or 5 then
print("Successfully created a Common Chest!")
else
if math.random(5,10) == 5 or 6 or 7 then
print("Successfully created a Rare Chest!")
else
if math.random(8,10) == 8 or 9 then
print("Successfully created an Epic Chest!")
else
print ("Successfully created a legendary chest!")
end
end
end
end
You are trying to use or on numbers to check the it contains the numbers.
Sorry in programming, it doesn’t work that way.
It’s truthy vs falsely, the or operator is left associative (at least in Lua and Python), so
print(1 or 2 or 3) --> 1
print(0 or 1 or 2) --> Lua: 0, Python: 1
print(false or 2) --> 2
== operator is calculated before the or operator so
print(1 == 2 or 3) --> 3
Please use “elseif” (or “elif” if you’re on Python or “else if” if you’re on C/C++C#) instead of “else” then “if”.
That’s ok. Just as long as its less than the chests previously it should be good. This currently is a PH, so I will balance it. Thanks for your help!