Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I name a set of parts in number order without manually doing it?

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! :)

3 comments

0

are they all the same part or different parts?

0

and are they all the same distance away from each other

0

They all look the same, they are all touching each other but not merging.

1 answer

✓ Accepted 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

0

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!

0

no worries. kinda in the middle of something but i can reply later

0

Ok! Thanks!

0

Sorry for a late reply. I got it working

0

Basically sorts the parts in a table based on their position in the workspace and names them

0

Thanks so much! I’ll try this out as soon as I get to my computer!

0

Kk Let me know how it goes.

0

cheers

0

So the script itself works, however it names the numbers in a random order. I might be doing something wrong with the axis though.

0

names the numbers in a random order?

0

can u show a gif?

0

It might be because the parts have a rotation?

0

How do I post an image?

0

https://snipboard.io/o1g3AT.jpg you can see 1 is in the middle of the model, not at the beginning.

0

can i have the model pls sorry for asking for so much

0

Here's the game: https://www.roblox.com/games/3946710635/Example no problem. Thanks for going through all this trouble!

0

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

0

ye, sorry i didn't reply sooner i completely forgot.

0

its ok :)

0

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

0

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

0

ok thanks, heres the model: https://www.roblox.com/library/3964878805/coaster thanks

0

any progress?

This discussion is preserved as it was. New answers, comments, and votes are closed.