I’m currently trying to make a luck based system for catching fish in a game im making, i have a table that sets out all the values but when i go to run the function it does get to the for loop. my current code:
lucktable = {
["Common"] = {1,70},
["Uncommon"] = {71,90},
["Rare"] = {91,97},
["Legendary"] = {98,100}
}
function GoThroughLuckTable(Input)
print("test")
print(lucktable)
for i, v in ipairs(lucktable) do
if Input > lucktable[v][1] and Input < lucktable[v][2] then
print(lucktable[v])
end
end
end
GoThroughLuckTable(72)
Instead of going through the whole thing it only prints
If I remember correctly when I was doing this last time I did this I had to change it to pairs instead of ipairs. The reasoning for this is because ipairs is for a table such as {1, 2, 3, 4, 5, 6} while pairs is more for iterating through per say instances inside of the workspace. Each Item inside of your lucktable is defined as an Instance according to ROBLOX when it is reading it therefore when they go to continue with ipairs it hits a NIL value and stops the loop, ipairs will always stop when it reaches a Nil value while pairs should continue with only returning Nil
This will return the table with the boundaries of the number you gave, if you want the name, you can either add a name variable inside the table or make a function with another table to get it
The ["__"] is like an index for it not its actual name, to get the name, add a vraibale called name next to your luck boundaries / just a string at the end andake it like this
print(lucktable[v][3]) --third index will be the name after adding it!
lucktable = {
["Common"] = {1,70,"Common"},
["Uncommon"] = {71,90,"Uncommon"},
["Rare"] = {91,97,"Rare"},
["Legendary"] = {98,100,"Legendary"}
}
function GoThroughLuckTable(Input)
print("test")
print(lucktable)
for i, v in ipairs(lucktable) do
if Input > lucktable[v][1] and Input < lucktable[v][2] then
print(lucktable[v][3])
end
end
end
GoThroughLuckTable(72)