How would I sort this table?

How would I sort this table by most to least kills?

gamedata[Player.UserId] = {
	(kills.Value)
}

Here is something I found

gamedata[Player.UserId] = { 4, 1, 3, 2 }

table.sort(gamedata[Player.UserId], function(a, b)
    return a > b
end)

Credits: winky_y

Instead you could just simply use table.sort() as it would automatically sort from least to the greatest.

I’m trying to sort the entire thing where u can see the player and the kills they have, so like this:

gamedata = {
   playerId = 5,
   playerId = 3,
   playerId = 1
}

Ah, I’ll try something out to see then

Remember that you’ll want to index the table by integers (using it as an array), and assuming you want to sort the array in-place, you can use table.sort

So, since UserId is and int64, the array will maintain order. So you can sort by

table.sort(gamedata, function(p1, p2) 
  return p1.kills > p2.kills
end)

You’ll need to insert into the table as

gamedata[player.UserId] = {
  kills = 10
}
1 Like

Thats literally the same thing I said (script) (just without the inserting the table part)

Thats not the same thing… your method wouldn’t work since you’re sorting the player’s table, not the whole gamedata.

1 Like

Then you could just add the reminants, example: add another child instance, I only provided a base example.