Hey, i’m looking for some help on this code.
I’m trying to check the player’s rank and access the player’s next rank.
Example: if rank.Value == "Starter" then nextRank == "Rookie"
Thanks for helping!
Hey, i’m looking for some help on this code.
I’m trying to check the player’s rank and access the player’s next rank.
Example: if rank.Value == "Starter" then nextRank == "Rookie"
Thanks for helping!
If I were you, I’d structure the table as such to take advantage of indexing:
local ranks = {
[1] = {
["Rank"] = "Starter",
["Requirement"] = 0,
["Multiplier"] = 1
},
[2] = {
["Rank"] = "Rookie",
["Requirement"] = 1e3, -- Suggestion: use scientific notation instead of making a redundant comment, it will save you the trouble of having to memorize what the magnitude of "K" means
["Multiplier"] = 2
},
[3] = {
["Rank"] = "Expert",
["Requirement"] = 2.5e4,
["Multiplier"] = 3
},
-- etc.
}
This way, you know the next rank is simply the rank at the index of the current player’s rank + 1:
if rank == ranks[1] then nextRank = ranks[2] end
Is there we can do that without having to change the numbers of this line manually?
Here you go
local ranks = {
Starter = {
Requirement = 0,
Multipier = 1,
},
Rookie = {
Requirement = 1000,
Multipier = 2,
},
Expert = {
Requirement = 25000,
Multipier = 3,
}
}
local rankslist = {"Starter", "Rookie", "Expert"}
local function getNextRank(name)
return rankslist[table.find(rankslist, name)+1]
end
So basically what you want to do is, have another table with the list of names,
Find the index of your “chosen rank” then add 1 to it to the next one,
Then call it to the rankslist table, if you want to call it directly from the ranks table you can easily alter it (mb for the english lol)
That was psuedocode; optimally, you’d know ahead of time what the player’s current rank was (you could just save the index of the player’s rank and refer to the table to get the next one)
This is very useful to me but how would I get the Requirement of the next rank?
Nvm I found out. I just had to put the function local function getNextRank
that you gave me inside the module, then call it.
Thanks a lot man!
sorry for the late i left for school, but no worries if theres anything else i’ll be going on and offline occasionally now so might be able to help
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.