This issue is probably easy to fix, I’m just a bit lost right now and don’t know how to fix it lol.
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.
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.
I also have 5 different Frame templates which come in different colors and styles:
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
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.
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.
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 ScrollingFrameto 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.
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
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)
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