Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

0
are they all the same part or different parts? royaltoe 5144 — 5y
0
and are they all the same distance away from each other royaltoe 5144 — 5y
0
They all look the same, they are all touching each other but not merging. happyhal75 32 — 5y

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago
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
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! happyhal75 32 — 5y
0
no worries. kinda in the middle of something but i can reply later royaltoe 5144 — 5y
0
Ok! Thanks! happyhal75 32 — 5y
0
Sorry for a late reply. I got it working royaltoe 5144 — 5y
View all comments (19 more)
0
Basically sorts the parts in a table based on their position in the workspace and names them royaltoe 5144 — 5y
0
Thanks so much! I’ll try this out as soon as I get to my computer! happyhal75 32 — 5y
0
Kk Let me know how it goes. royaltoe 5144 — 5y
0
cheers royaltoe 5144 — 5y
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. happyhal75 32 — 5y
0
names the numbers in a random order? royaltoe 5144 — 5y
0
can u show a gif? royaltoe 5144 — 5y
0
It might be because the parts have a rotation? happyhal75 32 — 5y
0
How do I post an image? happyhal75 32 — 5y
0
https://snipboard.io/o1g3AT.jpg you can see 1 is in the middle of the model, not at the beginning. happyhal75 32 — 5y
0
can i have the model pls sorry for asking for so much royaltoe 5144 — 5y
0
Here's the game: https://www.roblox.com/games/3946710635/Example no problem. Thanks for going through all this trouble! happyhal75 32 — 5y
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 happyhal75 32 — 5y
0
ye, sorry i didn't reply sooner i completely forgot. royaltoe 5144 — 5y
0
its ok :) happyhal75 32 — 5y
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 happyhal75 32 — 5y
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 royaltoe 5144 — 5y
0
ok thanks, heres the model: https://www.roblox.com/library/3964878805/coaster thanks happyhal75 32 — 5y
0
any progress? happyhal75 32 — 5y
Ad

Answer this question