How do I change the order of each frame?

This issue is probably easy to fix, I’m just a bit lost right now and don’t know how to fix it lol.

  1. What do you want to achieve? I’m trying to make a list of players in the server displayed on a ScrollingFrame and inside the ScrollingFrame there’s a UIListLayout and a UIPadding. All these items are located in the Workspace.
    image

  2. What is the issue? The issue is that whenever I add a Frame to the ScrollingFrame, the latest Frame added to the ScrollingFrame displays at the bottom. I want the latest ones to be added at the top.

This is what I want:

This is what I get:

I also have 5 different Frame templates which come in different colors and styles:
image

  1. What solutions have you tried so far? I’ve tried changing the LayoutOrder property with a
    for loop that changes the layout order of the children inside the ScrollingFrame to 0 before I add a new Frame.
--Note: The default LayoutOrder for each template is 1.
for i, v in pairs(templates:GetChildren()) do
	if v:IsA("Frame") then
		v.LayoutOrder = 0
	end
end

local Clone = NewTemplate:Clone()
Clone.Parent = ScrollingFrame

Which that for some reason didn’t work :confused:
It changes the LayoutOrder, but the frames for some reason stay in the same place.

If anyone could please tell me how to fix this, I would highly appreciate it.

2 Likes

They’re staying in the same place because none of them have a LayoutOrder higher than each other.

If you can always count on the max player size of the server being the same, you can set the first player’s frame’s LayoutOrder to that number, then every time a player joins, subtract one from the LayoutOrder, this should make the player’s frames go in order from when they joined, bottom being the most time ago, and top being most recent join.

Here are the frames:
image
In here they currently have their LayoutOrder set to 1.

--Note: The default LayoutOrder for each template is 1.
for i, v in pairs(templates:GetChildren()) do
	if v:IsA("Frame") then
		v.LayoutOrder = 0
	end
end

local Clone = NewTemplate:Clone()
Clone.Parent = ScrollingFrame

This script changes the LayoutOrder of the frames already inside the ScrollingFrame to a value of 0. The Frame that gets cloned still has a LayoutOrder of 1 because it isn’t inside the ScrollingFrame yet. Therefore, the LayoutOrder of the new Frame is higher from the rest of the frames.

The highest guis under the influence of a uilistlayout have a lower layout order.

0 is lower than 1 so it’s higher

In my Chat System, this is how I delete the oldest frame. Otherwise, you could retrieve the amount of Children the UI has, and substract the layout order accordingly.

local MaxMessages = 7

local function onChildAdded(child)
	local Messages = chatBG:GetChildren()

	if #Messages >= MaxMessages then
		Messages[1]:Destroy() -- Deletes oldest message frame
	end

	child.Position = UDim2.new(0.01, 5, 1, 0)
	updatePositions()
end

When I try that for some reason it changes the LayoutOrder, but the frames still stay in the same spot. I don’t understand why they don’t move.

Thanks for the idea tho…

I’m not trying to delete the frames by order, I’m trying to change the order of their Position.

Here’s my example of what I mean:
image

The UIListLayout is limited on its flexibility. If you’d want to change the order while keeping the UIListLayout, you’d have to map/position them manually based on the Y-Axis and sort it accordingly without the UIListLayout. (I could be wrong)

Oh, I get it. So what you’re trying to say is that while there’s a UIListLayout, the Frames all have the same LayoutOrder.

Well, any suggestions on how I can fix this? Removing the UIListLayout would leave all the frames stacked on each other which I don’t want.

I’ll just write it out for you.

local templates = {}

local function createTemplate()
	local Clone = NewTemplate:Clone()

	if #templates > 0 then
		table.insert(templates, Clone)
		
		for i, template in templates do
			template.LayoutOrder = #templates - i
		end
	end
	
	Clone.Parent = ScrollingFrame
end

You can’t change the Position of the Frame while there’s a UIListLayout.
image

Exactly, you’d need to remove it and code it manually, or trying to subtract the LayoutOrder.

1 Like

What happens if you change it to v.LayoutOrder = -5 instead maybe?

Sorry that was wrong before now I’ve edited it and it should work.

I tried the script and it doesn’t work.

Then how would your script even make a difference?

Unfortunately that doesn’t work.

What doesn’t work, is it the same order at last time or does it not create the uis?

No error message, but still the same order.

Are the uis not in the scrollingframe beforehand?