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

How i can make ipairs affect more stuff?

im making a script that changes the border color of my gui,but i dont want to make a spam of ipairs because my gui have alot of frames and textbuttons

this is the script i used that works fine (only affects one frame)

Console = script.Parent.Parent.Console
function Red()
    for _, child in ipairs(Console:GetChildren())do
        if child:IsA("TextButton") then
        child.BorderColor3 = Color3.new(255,0,0)
end
end
end

i tried this but it dint work

Console = script.Parent.Parent.Console
Music = script.Parent.Parent.Music
Gears = script.Parent.Parent.Gears

stuff = {Console,Music,Gears}
function Red()
    for _, child in ipairs(stuff:GetChildren())do
        if child:IsA("TextButton") then
        child.BorderColor3 = Color3.new(255,0,0)
end
end
end

1 comment

0

No easy way that I know of. However Pyrondon made this: https://forum.scriptinghelpers.org/topic/15/iterator-generator-for-multiple-tables/3

1 answer

✓ Accepted answer

Loop through your stuff table and iterate through that.

-Also changed your Color3 to Color3.fromRGB, because color3.new() uses percentages from 0 to 1.

local Console = script.Parent.Parent.Console
local Music = script.Parent.Parent.Music
local Gears = script.Parent.Parent.Gears

local stuff = {
	Console,
	Music,
	Gears
}

function Red()
	for _,ThingFromStuff in ipairs(stuff) do
		for _, child in ipairs(ThingFromStuff:GetChildren())do
			if child:IsA("TextButton") then
				child.BorderColor3 = Color3.fromRGB(255,0,0)
			end
		end
	end
end

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