I am making a highscore board that will display your ranking. The current code creates a table of all the scores(which are stored in a group filled with int values, the value being the score, and the name of the value being the already defined player name) , and then sorts the scores from greatest to least. However, I also need the name of the player to go along with the scores.
Basically, how would I sort the table while keeping the names defined so I can put it next to their score? The actual player name is stored in v.Name (Which I put a comment in there for) I just need to figure out how to take that name and display it with the rest of them.
local values = {}
for _, v in pairs(PlayerNames:GetChildren()) do
--v.Name is where the string is stored!
table.insert(values, v.Value)
end
table.sort(values, function(a, b)--Sort the numbers
return (a > b)
end)
place=0
for index, value in ipairs(values) do--Creates a new frame that contains the player score
place=place+1
local FrameC=HighscoreScr.Frame1:clone()
FrameC.Parent=HSFrame
--FrameC.ImageLabel.PlayerText=PLAYERNAME I NEED TO FIND!
FrameC.Damage.Text=value
FrameC.Visible=true
FrameC.Place.Text=place
end
print("Number of Scores: "..(#values))
HSFrame.Visible=true

1 comment
Why wouldn't you just use
table.sortand save 8 lines of code?