If you don't understand, I have a set of about 100 Parts in order in a line. I want to name them starting at 1 to 100. How could I do this without wasting an hour? I don't know if it's possible, but please give some suggestions! :)
How can I name a set of parts in number order without manually doing it?
1 answer
partsTable = game.Workspace.Model:GetChildren()
for i = 2, #partsTable do
local key = partsTable[i]
j = i - 1
while (j >= 1 and partsTable[j].Position.Z > key.Position.Z)do
partsTable[j + 1] = partsTable[j];
j = j - 1;
end
partsTable[j + 1] = key;
end
for i, v in ipairs(partsTable)do
v.Name = i
end
23 comments
I'm sorry, I forgot to mention that the parts aren't in a straight line, It is in the shape of a roller coaster without track. It has hills and turns. This is my first post so I'm kind of confused still. I have all the parts already in place, I just would like a way to name them in order. Sorry!
no worries. kinda in the middle of something but i can reply later
Ok! Thanks!
Sorry for a late reply. I got it working
Basically sorts the parts in a table based on their position in the workspace and names them
Thanks so much! I’ll try this out as soon as I get to my computer!
Kk Let me know how it goes.
cheers
So the script itself works, however it names the numbers in a random order. I might be doing something wrong with the axis though.
names the numbers in a random order?
can u show a gif?
It might be because the parts have a rotation?
How do I post an image?
https://snipboard.io/o1g3AT.jpg you can see 1 is in the middle of the model, not at the beginning.
can i have the model pls sorry for asking for so much
Here's the game: https://www.roblox.com/games/3946710635/Example no problem. Thanks for going through all this trouble!
Thanks! Everything seems to work great except the beginning which I can manually do! You just made everything with my new game so much easier lol. Thanks again! :D
ye, sorry i didn't reply sooner i completely forgot.
its ok :)
oof. I just tried it out on a complete coaster model and its all mixed up. I think if I mess with the axis by making the coaster turn, its messing it up
the code above only works on one axis. i'm studying for an exam right now but if you send me the roller coaster model i can try to get it working for all axis
ok thanks, heres the model: https://www.roblox.com/library/3964878805/coaster thanks
any progress?
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
are they all the same part or different parts?
and are they all the same distance away from each other
They all look the same, they are all touching each other but not merging.