So, I have these attachments, and I want to get them in a specific order for a script that tweens a part to each attachment, so i would get the parts in order, but the problem is making it so the attachments are retrieved in a specific order.
Let’s say the part starts at attachment 2, the order would be:
3,4,1,2
or if i start from attachment 3:
4,1,2,3
Have the attachaments stored inside a table like @Kaid3n22 said and iterate over the table, if you’re not exactly sure of how to do that you can check out this: Tables | Roblox Creator Documentation
But how could i get the values in a specific order for every attachment, I can’t do it manually because in my game this thing has 13 attachments.
The order should be:
The current attachment’s number, then every other attachment with a higher numbe in order from lowest to highest, then every nuber below the current attachment’s number, also ordered from lowest to highest.
What im trying to do is to get the attachments in a specific order depending on what attachment the part is currently on. In the example I gave, I want the part to go around every attachment clockwise, so the correct order of attachments changes depending on which one the part started in
local index = 3
local AmountLookedAt = 0
local Max = 4
repeat
local Attachment = Model:FindFirstChild("Attachment"..index)
-- do stuff
AmountLookedAt += 1
index += 1
if index>Max then
index = 1
end
until AmountLookedAt == Max
From what I understand, you want to tween a part from 1 attachment to the next to make the part follow a path.
You would need to set the attachments in a numerical order to make things easier
Instead of an i,v in ipairs loop, we use a for = 1, #attachments loop to get the numerical order because an i, v in ipairs loop may pick the attachments in the wrong order
local attachmentsFromContainer = attachmentContainer:GetChildren()
for i = 1, #attachmentsFromContainer do
local thisAttachment = attachmentContainer:FindFirstChild(tostring(i))
-- this will get the attachments in a numerical order from 1 to the max number of attachment
-- so you would tween the part to thisAttachment here
end
Iterating through the array will return every attachement in the order you put them in so you can manipulate them by picking the correct one from the array