How do I organize Number Values in order depending on there value?

I’m making a game that requires the player to choose a plot, and I made a function to find a open plot, but I need the function to return the open plots in order depending on the plot number.
1, 2 exedra
Plot Numbers:
Screenshot 2022-08-11 110445

function:

function FindOpenPlot()
			local Plots = game.Workspace.Plots:GetChildren()
		for i,v in pairs(Plots) do
			if v.Variables.Claimed.Value == false then
                               return (Plot Names in order of there Number)
				end
			end

You can sort the table using table.sort:

function FindOpenPlot()
	local Plots = game.Workspace.Plots:GetChildren()
	local OpenPlots = {}
	
	for _, v in pairs(Plots) do
		if v.Variables.Claimed.Value == false then
			table.insert(OpenPlots, v)
		end
	end
	
	table.sort(OpenPlots, function (a, b)
		return a.Variables.Claimed.Value < b.Variables.Claimed.Value
	end)

	return OpenPlots
end
1 Like

if your using a

or

you could use SortOrder

and set it to LayoutOrder

then all you would need to do is

set the LayoutOrder for the guiobjects so that they show in the order you want

plotGui.LayoutOrder = plotNumber
1 Like