Hey there!
So, I have a script where certain frames are parented once an event is fired. However, I want to do it in numerical order for an inventory, starting at 1 (obviously)
This is the code I used:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remotes = ReplicatedStorage.Remotes
remotes.ItemUpdate.OnClientEvent:Connect(function()
for i, v in ipairs(script.InventorySlots:GetChildren()) do
print(v)
v.Parent = script.Parent.Frame
break
end
end)
Now, here’s the thing. It starts at 2, but works fine past that.
UIGridLayoutOrder >> List Layout
For each frame v.LayoutOrder = tonumber(v.Name)
Reading your problem and images isn’t enough to properly understand what you actual problem is as you’ve only stated you want it in numerical order yet inventory slots vs hotbar capacity are different
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remotes = ReplicatedStorage.Remotes
for i, v in pairs(script.InventorySlots:GetChildren()) do
v.LayoutOrder = tonumber(v.Name)
end
remotes.ItemUpdate.OnClientEvent:Connect(function()
for i, v in ipairs(script.InventorySlots:GetChildren()) do
print(v)
v.Parent = script.Parent.Frame
break
end
end)
The problem is that its choosing frame number 2, not that it appears in the wrong order when parented to the frame with the UIGridLayout.
I don’t understand why this is an issue for you though. Regardless if you want it to Re-parent in order then you will need to first create a table with the children, then use table.sort.
Example:
local myFrames = script.InventorySlots:GetChildren()
table.sort(myFrames,function(a,b)
return tonumber(a.Name) < tonumber(b.Name)
end)