Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer
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

? 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

This discussion is preserved as it was. New answers, comments, and votes are closed.