I'm making a friends list ui and it's not working as intended.
Basically, I want it so it sorts the player's friends that are online at the top and the rest who are offline lower at the bottom, but I don't understand how to use table.sort functions or how to use LayoutOrder, it's very very vague on the wiki and I don't understand what they say, they don't even provide examples on it.
Can someone please elaborate on how to use LayoutOrder and table.sort function because it's not clear.
This script keeps erroring at the lines of the table.sort function. I don't know what's wrong with it..
Error: attempt to index field '?' (a nil value)
local friendsPages = game:GetService('Players'):GetFriendsAsync(player.UserId)
local friendsTab = {}
local labels = {}
for i, friends in pairs(friendsPages:GetCurrentPage()) do
local newLabel = PlaceHolder:Clone()
newLabel.Visible = true
table.insert(friendsTab, friends.Username)
table.insert(labels, newLabel)
newLabel.Parent = PlaceHolder.Parent
newLabel.LayoutOrder = i
newLabel.PlayerName.Text = friends.Username
PlaceHolder.Parent.CanvasSize = UDim2.new(0, 0, 0.2075 * #friendsTab, 0)
newLabel.Avatar.Image = 'https://www.roblox.com/headshot-thumbnail/image?userId=' .. friends.Id ..'&width=420&height=420&format=png'
table.sort(friendsTab, function(a, b)
return friends[a].IsOnline > b
end)
end

6 comments
Can you post the error? Why just say "it's erroring" and not post the error.
My bad I forgot to add the error. I edited it.
What line?
I have hundreds of lines of code, I just took a section of the main code for it. I thought stating that the error was occuring because of the table.sort function would suffice, but I guess not. Anyways, it's line 17
You're trying to compare a boolean with something that isn't.
Well I don't understand how functions work inside table methods, I don't know what the parameters are either.. How do I fix it?