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

How i can make ipairs affect more stuff?

Asked by 7 years ago

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
0
No easy way that I know of. However Pyrondon made this: https://forum.scriptinghelpers.org/topic/15/iterator-generator-for-multiple-tables/3 OldPalHappy 1477 — 7y

1 answer

Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

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
Ad

Answer this question