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

How to grab all the children of a model that all have the same name?

Asked by 4 years ago
Edited 4 years ago

I have 5 parts in a model named "Part" and I don't know how to change the properties of the children. The ? is something I feel like is missing that needs to be fixed.

This script is for a window script, when it becomes 16:00 it changes the glass in the model to the items below.

glass = script.Parent:GetChildren()
while true do
    if game.Lighting:GetMinutesAfterMidnight() > 16 * 60 then
        wait(math.random(10,50))
        for i, v in pairs(glass) do
            if glass.Name == "Part" then
                ?.Transparency = 0
                ?.Material = Enum.Material.Neon
                ?.BrickColor = Color3.new("White")
            end
        end
    end
    if game.Lighting:GetMinutesAfterMidnight() > 23 * 60 then
        wait(math.random(20,50))
        for i, v in pairs(glass) do
            if glass.Name == "Part" then
                ?.Transparency = .6
                ?.Material = Enum.Material.Glass
                ?.BrickColor = Color3.new("Dark Stone Grey")
            end
        end
    end
end

I would appreciate it if I could get some insight on how to make this for script thing work.

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
glass = script.Parent:GetChildren()
while true do
    if game.Lighting:GetMinutesAfterMidnight() > 16 * 60 then
        wait(math.random(10,50))
        for i, v in pairs(glass) do
            if v.Name == "Part" then
                v.Transparency = 0
                v.Material = Enum.Material.Neon
                v.BrickColor = BrickColor.new("White")
            end
        end
    end
    if game.Lighting:GetMinutesAfterMidnight() > 23 * 60 then
        wait(math.random(20,50))
        for i, v in pairs(glass) do
            if v.Name == "Part" then
                v.Transparency = .6
                v.Material = Enum.Material.Glass
                v.BrickColor = BrickColor.new("Dark Stone Grey")
            end
        end
    end
end

there we go, checking if the name is part and if it is then changes those properties also to change the brickcolor you use BrickColor.new and not Color3.new Color3.new wants a value and not a string

Ad
Log in to vote
0
Answered by
Thetacah 712 Moderation Voter
4 years ago

? should be v.

glass = script.Parent:GetChildren()
while true do
    if game.Lighting:GetMinutesAfterMidnight() > 16 * 60 then
        wait(math.random(10,50))
        for i, v in pairs(glass) do
            if glass.Name == "Part" then
                v.Transparency = 0
                v.Material = Enum.Material.Neon
                v.BrickColor = Color3.new("White")
            end
        end
    end
    if game.Lighting:GetMinutesAfterMidnight() > 23 * 60 then
        wait(math.random(20,50))
        for i, v in pairs(glass) do
            if glass.Name == "Part" then
                v.Transparency = .6
                v.Material = Enum.Material.Glass
                v.BrickColor = Color3.new("Dark Stone Grey")
            end
        end
    end
end

Answer this question