Sorting players by a undetermined integer through list

So uh… I’m trying to make a code that orders the players greatest to least, based on how many eggs they collect. The intvalue is called EggCount, and is stored inside the player. The error message is “attempted to index a number with a number”. I’m just confused right now.

				for i,v in ipairs(Players:GetChildren()) do
					v = {v,v.EggCount.Value}
					table.sort(v, function(a,b)
						print(v)
						return a[2] > b[2]
					end)
				end

Any help would be appreciated, I’m going on vacation in 3 hours, so I might take a while to check in.

1 Like
local players = game.Players:GetPlayers()

table.sort(players, function(a,b)
	return a.EggCount.Value > b.EggCount.Value
end)

print(players)

Hello, this should work, check the console for the results (table not printing in F9 menu)

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.