Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Sorting table from highest to lowest?

I'm attempting to write a script where it takes the table and sorts out the lap number from highest to lowest. The thing is, it correctly prints out the first player, but the players afterwards bug out.

Table script:

local allPlayers = game.Players:GetPlayers()

table.sort(allPlayers, function(a, b)
	return a.Lap.Value > b.Lap.Value
end)

while wait(0.001) do
	for i,v in next, allPlayers do
		print(v.Name .. ": " .. i .. "th")
	end
end

PlayerInstance script:

local allPlayers = game.Players:GetPlayers()
local test = game.Players.LocalPlayer:GetFullName()

for _, player in pairs(allPlayers) do
	if player.Character then
		if  test ~= "Player.Sxerks2" then
			-- was only a test
			local lapNum = Instance.new("IntValue", game.Players.LocalPlayer)
			lapNum.Name = "Lap"
			lapNum.Value = 2
		end
		
		local lapNum = Instance.new("IntValue", game.Players.LocalPlayer)
		lapNum.Name = "Lap"
		lapNum.Value = 1
		
		local checkpoint = Instance.new("IntValue", game.Players.LocalPlayer)
		checkpoint.Name = "Checkpoint"
		checkpoint.Value = 0
	end
end

Thanks!

3 comments

0

What is this "table?" Is it part of the leader board? Or is it an object. If it is a part, then you need to put workspace.table

0

Wait... what!?? table.sort? Has that always been a thing?

0

@NewVoids Yeah, lol. It sorts data in a table by numerical order, then alphabetical order.

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.