I’m trying to make code that would parent gui objects to a scrolling frame and have them be organized by ui grid layout. It does parent the objects, but it doesn’t organize them properly, the same way they would be organized if i tossed them in manually in edit mode. How could this be fixed?
This is part of my code:
for x, truck in ipairs(replicatedStorage:WaitForChild("Trucks").Vehicles:GetChildren()) do
local newCard = replicatedStorage:WaitForChild("Gui").VehicleCard:Clone()
newCard.Parent = gui.Frame.Scroll
newCard.LayoutOrder = x
newCard.Name = truck.Name
end
You’re not getting their current layout order, only setting it to the current index (x) of your for loop. Makes sense? So you’ll have to manually set the layout order of each truck and then you can parent them in however you want to without even setting the layout order using script.
You could also script something that gives the truck GUI objects layout orders BASED on their price/speed for example
Extra note: u don’t have to wait for child on replicated storage
I tried setting it to sort items alphabetically, but it still puts them in the same place. The code is placed in a localscript, could that be the reason why?
Since I got no answer, as of right now I’m just using a for loop to organize the list instead of using uigridlayout. If you have an answer as to what might be causing my problems, please let me know. (i’m not going to make a card for each of the truck in-game)