A way to change parts that has a value in it

Hello, devs!

I’ve ran into an issue and I couldn’t find a way to solve it, this may be hard to explain, but I’ll try my best to make it as clear as possible.

I’m looking for a way to apply a change to a part that has a value inside it.

let me explain:

as most of you know, “in pairs” loop is a loop that can go through every part inside a model and change it to whatever the person requests the part to be like (look in Example1).

Example1
for i,v in pairs(game.Workspace.Model:GetChildren()) do
v.BrickColor = BrickColor.new("Really red")
end

In Example1 a code turns parts inside a model and ONLY inside that model into the “Really red” color.

however, I’m looking for a way to make parts inside that model to turn red ONLY if they have a value inside it (look in Example2)

Example2

image

conclusion: I want parts to change their color for example if it has a value inside it, regardless if it uses a pairs loop or not, buy only using 1 local script.

You would just use :FindFirstChild() to find the value inside it.

1 Like

yeah i think you can just use FindFirstChild()

1 Like

would that be working with something like this

image

a model inside a model that contains parts that has a value inside it

If you are trying to do it like that, I suggest you use :GetDescendants() on the main model. This function will get ALL children of the model, including the children of the children model (I may be explaining bad, but you can check it from the Developer page)

1 Like
for i, v in pairs(game.Workspace.Model:GetChildren()) do
    if v:FindFirstChild("Looper", true) then
        v.BrickColor = BrickColor.new("Really red")
    end
end
2 Likes

that “GetDescendants()” thing for whatever seems to be working, thx for your help, you just saved 4 hours of my time in 10 min.

1 Like