I’m trying to make a table where I can put the name’s and racing times of players in a race. I want to sort them from least time to greatest time, and move around the players to be in order.
Basically, I want it to do this.
Before Sort:
local PlayerAssignments = {
Player1 = {Name = "FirstPlayer", Time = 10},
Player2 = {Name = "SecondPlayer", Time = 1}
Player3 = {Name = "ThirdPlayer", Time = 3},
Player4 = {Name = "ForthPlayer", Time = 7}
}
After Sort:
local PlayerAssignments = {
Player2 = {Name = "SecondPlayer", Time = 1}
Player3 = {Name = "ThirdPlayer", Time = 3},
Player4 = {Name = "ForthPlayer", Time = 7}
Player1 = {Name = "FirstPlayer", Time = 10},
}
Is there a way to use table.sort with this? I was able to use it on other tables, but since this one has a bunch of variables and tables, it’s confusing on how to do it. Also, let me know if you know of a better way of organizing the same stats in a table, I just thought of doing this to keep it tidy in one main table.
Thanks for the help!