local Players = game.Players
local PlayerInfoUI = script.PlayerInfoUI
local ClassT ={
[10^3] = "Average Class",
[10^4] = "Decent Class",
[10^5] = "Middle Class",
[10^6] = "Rich Class",
[10^7] = "Luxurious Class",
[10^8] = "Governer Class",
[10^9] = "Presidential Class"
}
local RankT ={
[1] = "Newbie Rank",
[10] = "Decent Rank",
[50] = "Pro Rank",
[75] = "Fighter Rank",
[100] = "Old Player Rank"
}
Players.PlayerAdded:Connect(function(player)
local Level,Money = player:WaitForChild("Level"),player:WaitForChild("Money")
local Char = player.Character or player.CharacterAdded:Wait()
local NC = BrickColor.new(player:WaitForChild("NameColor").Value)
local C = PlayerInfoUI:Clone()
C.Parent = Char:WaitForChild("Head")
C.PName.Text = player.DisplayName.."(@"..player.Name..")"
C.PName.TextColor3 = NC.Color
while player do
local Rank
for i,v in pairs(RankT) do
if i <= Level.Value then
Rank = v
end
end
print(Rank,Level.Value)
C.Rank.Text = Rank
wait()
end
end)
Ok so I want my code to set a players rank from 1 of the 5 ranks in RankT and I am suffering doing that.
Example:
Lets say the players level is 1 his/her rank is Newbie Rank Now lets say the players rank is 5 his/her rank SHOULD BE Newbie Rank NOW lets say that the players rank is 11 or 12 or 49 I want his/her rank to be Decent Rank
So when you call a for loop method on a table, it will cycle through the index as a number because the index is a numerical position, AKA a key in the table. For loops cycle through a certain amount of iterations for the code block.
For example, this table has 2 indexes and will print out the 2 index keys and values in order.
for i,v in pairs(testDictionary) do
print(i, v)
end
--[[
Console:
FruitName Lemon
FruitColor Yellow
]]--
However, for a dictionary, you can assign the index as a string variable and it will keep the same key.
When you assign a number to the index’s key, you are defining the index as the value, and the value of the index as a key. Essentially, the value and index are incorrectly labeled.
Dictionaries aren’t indexed with sequential numbers one through number of items/entries in the table, they use custom keys/fields and as such the table needs to be indexed with those keys/fields in order to access/fetch/retrieve the values assigned/associated to them.