Right now I'm trying to sort a list of players by their level that is in their player

SortByLevel = function()
	local tab = {}
	for k,v in ipairs (game.Players:GetChildren()) do
		repeat wait() until v:FindFirstChild("Level")
		table.insert(tab,{v.Level.Value,v.Name})
	end
	table.sort(tab)
	for i = #game.Players:GetChildren(), 1, -1 do
		local n = tostring((#game.Players:GetChildren() - (i-1)))
		body:FindFirstChild(n).Text = n..". "..tab[n][2]
	end
end

So I get the error saying that the line where it sets the text is indexing a nil value, how do I fix this? I'm sure this is some simple solution I just have never made a leaderboard before...

4 comments

0

Are you allowed to insert tables within tables using table.insert?

0

Why would you need to just make them separate tables and use the ""for i,v in pairs() do""

0

Where would I put the tables then?

0

How did I get down voted for the comment above? That makes no sense....