function DisplayRanks.getRankName(Number)
for _, Ranks in pairs(DisplayRanks.Ranks) do
if (Number) < 0 then
if (Number) < Ranks.Reputation then
return Ranks
end
else
if (Ranks.Reputation) > 0 then
if (Number) > Ranks.Reputation then
return Ranks
end
end
end
end
end
return DisplayRanks
So you want it to return the rank which has the highest reputation, while still lower than the supplied number?
If that is the case, then this should work:
local ranks = {
Rank0 = {
Reputation = 10
},
Rank1 = {
Reputation = 1000
},
Rank2 = {
Reputation = 2000
}
}
function getRank(number)
local currentMatch = nil
for rankName, values in pairs(ranks) do
if values.Reputation > number then continue end -- Skip if required reputation is too high
if not currentMatch or currentMatch.Reputation < values.Reputation then
currentMatch = {
Name = rankName,
Reputation = values.Reputation
}
end
end
if not currentMatch then return end
return currentMatch.Name
end
print(getRank(1999)) -- Rank1