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

How do I go through a number ordered model and rename the children to also be number ordered?

Asked by 3 years ago
Edited 3 years ago

I have the InCommand plugin to make my life easier but in a power user way but there's something I've never been tought to (I learned scripting through youtube tutorials) and that is... going through loops and doing things to make it ordered by adding an incremental number at the end.

so, I use a temporary script to check if there's any problems and there was but I fixed it and, it still didn't work because I literally don't know how to do that kind of thing, I was never tought that.

Script:

local model = workspace.ServerRoom

for i = 1, 16, 1 do
    for k, v in pairs(model["ServerPack"] .. i:GetChildren()) do
        for j = 1, 10, 1 do
            v.Name = "Box" .. j
        end
    end
end

Error: Runtime error in InCommand script: ServerPack is not a valid member of Model "Workspace.ServerRoom" (x2) - Studio

0
Is there an instance named ServerPack in ServerRoom? CrunchChaotic 139 — 3y
0
yes, it's a model. They're all manually number ordered. (What I mean by "manually" is I renamed them in studio) User#39895 0 — 3y
0
it's basically like this: ServerPack1 ServerPack2 ... etc User#39895 0 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Found the issue. So basically this:

model["ServerPack"] .. i:GetChildren()

would be like saying

model.ServerPack..i 

which would result in an error but since ServerPack Doesn't exist it created this error: Runtime error in InCommand script: ServerPack is not a valid member of Model "Workspace.ServerRoom" (x2) - Studio So if you move the '..i' into the brackets it should work as normal.

model["ServerPack"..i]:GetChildren()
0
Thanks! User#39895 0 — 3y
0
Well, it did fix the problem but now, How do I make it to number order it for me? for example: Box1 all the way to Box10 User#39895 0 — 3y
0
Because I am so new to for loops (except for for i, v in pairs loops) User#39895 0 — 3y
0
It didn't number it? CrunchChaotic 139 — 3y
View all comments (5 more)
0
seems like it should work CrunchChaotic 139 — 3y
0
I mean it can rename all children, but all of them is going to be the same name as the first one User#39895 0 — 3y
0
I want the number to be incremental, not the same name for every other child. User#39895 0 — 3y
0
Remove the 'for j = 1, 10, 1 do' and change 'v.Name = "Box" .. j' to 'v.Name = "Box" .. k' and that should work. CrunchChaotic 139 — 3y
1
TYSM It works perfectly as expected now! lemme save that script so it'd take less time in the future! :)) User#39895 0 — 3y
Ad

Answer this question