How to get string out of table

I’m trying to give number tiers by making a table with the name and the numbers it should be between, but idk how to get the name.

How the table looks like:

local tiers = {
	["Common"] = {40,50},
	["Uncommon"] = {30,40},
	["Rare"] = {20,30},
	["Epic"] = {10,20},
	["Legendary"] = {5,10},
	["Godly"] = {0,5}
}
local keys = {}
for key, _ in pairs(tiers) do table.insert(keys, key) end

print(keys) --{"Common", "Uncommon", "Rare", "Epic", "Legendary", "Godly"}
print(keys[1]) --"Common"
print(keys[3]) --"Rare"
print(tiers[keys[1]]) --{40,50}

table.find returns index from value within a table, in this case, the tier.

You can do,

Table.FindString:("Your String Here.")

Sorry for the confusion, here is the correct code.

table.find(Table,WhatToFind)

i think he means how to get the name that corresponds to the value between its bounds

heres a function that returns which tier the value fits into

function getName(value)
  for name, bounds in pairs(tiers) do
    local lowerBound = bounds[1]
    local upperBound = bounds[2]

    if value < lowerBound or value > upperBound then continue end

    return name
  end
end
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.