How can I adjust every object i want in one sentence?

Hello there! so as you might see, I’m working on a Game Launcher for My Community.

I want to add like a Light mode, and a dark mode.

I want the script to change a color of every frame that is included in one sentence instead of changing the colors of the frames separately.

this is the script, you might understand:
obviously, the script ain’t gonna work, but I want it to do it like this:

local activatedValue = script.Parent
local frame1 = script.Parent
local frame2 = script.Parent.Parent.test1
local frame3 = script.Parent.Parent.test3




local Frames = {frame1, --The one sentence thing
frame2, 

frame3

}

Frames.BackgroundColor3 = Color3.fromRGB(155,155,155) --Change the color of every one of them

support is appreciated!

1 Like
local activatedValue = script.Parent
local frame1 = script.Parent
local frame2 = script.Parent.Parent.test1
local frame3 = script.Parent.Parent.test3




local Frames = {
frame1;
frame2; 
frame3
}

for _,frame in ipairs(Frames) do
   frame.BackgroundColor3 = Color3.fromRGB(155,155,155)
end

You have to use a loop that goes over each iteration of the table, in this case that would be a for i,v in pairs loop. In this particular instance I’ve left Index (or i) blank using _, and I’ve used frame to define the value, which in this case inherently defines the frames.

From there you can treat the value “frame” as an object and change it’s background color as usual.

3 Likes

You should be using ipairs to loop through arrays.

4 Likes

Oh, I didn’t even catch my typo there, thank you for pointing it out.

1 Like

I’d just like to point out that you don’t always wanna use ipairs, it depends completely on use-case. If one of those frames were to be destroyed then ipairs would stop on that index.

Right right, my fault I forget that not all references to the object are cleared.

Calling :Destroy() by itself won’t remove the instance from the table. It will just leave behind a reference to an instance that is locked and has no parent.

Doing something like Frames[2] = nil would mess it up though, since ipairs is meant for arrays with sequential indices starting at 1.

1 Like