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

How do I make all parts in a model, that's in a model do something?

Asked by
Peeshavee 226 Moderation Voter
8 years ago

To be specific, I have 4 models, that are in a model called "all". In those 4 models, there are parts. I separated them into models to create patterns on the tiles. What I want is, to make all the parts in the models, to change color. Here's what I have, but it doesn't work.

local outter = game.Workspace.all.outter:GetChildren()
local second = game.Workspace.all.second:GetChildren()
local third = game.Workspace.all.third:GetChildren()
local last = game.Workspace.all.last:GetChildren()
local all = game.Workspace.all

for g = 1,3 do
for i,v in pairs(outter,second,third,last) do
    v.BrickColor = BrickColor.new("Institutional white")
    v.Material = "Neon"
    wait(0.5)
    v.BrickColor = BrickColor.new("Really black")
    v.Material = "SmoothPlastic"
end
end

So, what I'm doing here(I think) is returning ALL the parts in ALL the models, ALL at once. But this doesn't work. Any ideas? All help is appreciated!

0
Didn't you ask a question very similar to this yesterday? OldPalHappy 1477 — 8y
0
No, yesterday I asked how to do GetChildren() twice in one model. And even if I did, how is that relevant... Peeshavee 226 — 8y
0
Because you'd have the children of children and you'd just use `for i,v in pairs(all) do` you dip User#6546 35 — 8y
0
Yes, but I didn't understand your answer yesterday ._. Peeshavee 226 — 8y
View all comments (2 more)
0
Then you can't do this I'm sorry but you're too special to use a function that was written for you which did exactly what you ask, so you really can't do this at all. User#6546 35 — 8y
0
If I don't understand code, what's the point of using it? Just because you wrote code for me that did what I wanted it to, doesn't mean it'll teach me. I want to learn how it works. Pasting code that works, that I don't understand, defeats the purpose of me learning. Peeshavee 226 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

So outer, second, third, and last are the four "Patterns" you have created

It'd make more sense to call the "all" variables first but that's not the problem.

You have your loop g = 1,3 running 3 times, so I'm going to assume you only want your thing to run 3 times and leave it.

Basically your problem is, You want to run a loop and find all of the models inside of "all" and then run a loop for each individual model within it, correct?

Using an in pairs loop is your way to go.

local all = game.Workspace.all -- Where the models are stored
-- We don't really need all of the seperate variables for the outter and such

for g = 1, 3 do -- Keeping what you had previously.
    for ModelNum, OnModel in pairs(all:GetChilren()) do
        -- ModelNum is just the # of the loop compared to the total
        -- Instead of using an extra variable for the GetChildren() you can do it right in the loop, both work.
        -- OnModel is the Thing we find, in this case Hopefully a Model

        if OnModel.ClassName == "Model" then
            -- We're checking if the thing we found is a model like we hope.
            for NextNum, NextPart in pairs(OnModel:GetChildren()) do
                -- Now we run through all of the members of "OnModel" which should be your group of tiles 
                 NextPart.BrickColor = BrickColor.new("Institutional white")
                  NextPart.Material = "Neon"
                  wait(0.5)
                 NextPart.BrickColor = BrickColor.new("Really black")
                  NextPart.Material = "SmoothPlastic"
                    -- Only problem here is that you'll run into the issue of the parts only changing one at a time due to the wait.

            end
        end
    end
end

I don't know if you wanted them to all be different, change together, or such so I'll leave that portion to you.

This should give you some idea of where to go though, If you can't figure out how to remove the wait and get it to work just let me know and I'll help you out.

0
Ya..I'm having problems..As you said, it only works one at a time. Do you know any way to fix this? Your help is very much appreciated! Peeshavee 226 — 8y
Ad

Answer this question