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!
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.