How can I sort players names in alphabetic order

I’ve heard that you can use Table.Sort for that stuff but here in my code I’m not using tables but cloning a frame and inserting it into a GUI and want to sort the players name so It wouldn’t be so random

game.ReplicatedStorage.MatchEnd.OnClientEvent:Connect(function()
	local players = game.Teams["Bright blue Team"]:GetPlayers()
   	local Ypos = 0.25
	local End = script.Parent
	End.Enabled = true
	
	End.Frame:TweenPosition(UDim2.new(0.31, 0,0.273, 0), "Out", "Bounce", .5)

    
	for _,Player in pairs(players) do
		local Copy = script.Sample:Clone()
		wait(0.1)
		Copy.Parent = script.Parent.Frame.Left
		Copy.Visible = true
		Copy.LeftMate1.Text = Player.Name
		Copy.Position = UDim2.new(0.028,0,Ypos,0)
		
		Ypos = Ypos + 0.12
	end
	wait(3)
	End.Frame:TweenPosition(UDim2.new(0.31, 0,1, 0), "Out", "Bounce", .5)
	wait(2)
	End.Enabled = false
	for i,v in pairs(End.Frame.Left:GetChildren()) do
		if v.Name == "Sample" then
			v:Destroy()
			Ypos = 0.25
		end
	end
end)
1 Like

Omg please dont position list ui manually

Cant you use a UIListLayout and then change layout to Name

1 Like

I never used those things so it’s like dark forest for me

Its super easy :slight_smile:
You just put the UIListLayout into a frame and when you insert something into the frame it gets positioned automatically in a list format position

Heres a video i found

Ill try thanks for the idea and see if it works

You can try using table.sort on the player list.

This may help:

I added the sorting and changed the loops from pairs loops to ipairs loops.

game.ReplicatedStorage.MatchEnd.OnClientEvent:Connect(function()
    local players = game.Teams["Bright blue Team"]:GetPlayers()
    table.sort(players, function(a, b) return a.Name > b.Name; end)
   	local Ypos = 0.25
	local End = script.Parent
	End.Enabled = true
	
	End.Frame:TweenPosition(UDim2.new(0.31, 0,0.273, 0), "Out", "Bounce", .5)

    
	for _,Player in ipairs(players) do
		local Copy = script.Sample:Clone()
		wait(0.1)
		Copy.Parent = script.Parent.Frame.Left
		Copy.Visible = true
		Copy.LeftMate1.Text = Player.Name
		Copy.Position = UDim2.new(0.028,0,Ypos,0)
		
		Ypos = Ypos + 0.12
	end
	wait(3)
	End.Frame:TweenPosition(UDim2.new(0.31, 0,1, 0), "Out", "Bounce", .5)
	wait(2)
	End.Enabled = false
	for i,v in ipairs(End.Frame.Left:GetChildren()) do
		if v.Name == "Sample" then
			v:Destroy()
			Ypos = 0.25
		end
	end
end)
1 Like