Hello, I am trying to make it so that when you press a button it would change the brickcolour
of the children of a folder.
I remember doing something like this once but I completely forgot how I did it.
How would I phrase a for
statement to do this?
This is what I have so far, I don't know where to go about doing it.
1 | for i = 1 , v do -- I know I need to specify v I was thinking something like v = folder:GetChildren but that didn't work unless I did it wrong. |
2 |
3 | end |
Thank you in advance!
for a folder, as an object, you can do
think of i as the number its on and v as the specific value, for get children
1 | for i,v in ipairs (Folder:GetChildren()) do -- or descendants also ipairs or pairs |
2 | if v:IsA( "BasePart" ) then |
3 | v.BrickColor = BrickColor.new() |
4 | end |
5 | end |
for tables, think of v as the answer to the index and i as the number its on
for dictionaries its the same but think of i as not a number but the specific value its on for example
{"A","B"} as a normal table 1 gets A and 2 gets B but in a dictionary, {["B"] = "A",["OQ"] = "OP",} on the dictionary, 1 is equivalent to B because thats the name of the "index" so to say
a dictionary,
for i,v in pairs({["B"] = "A",["OQ"] = "OP"}) do print(v) -- prints A then OP print(i) -- prints B then OQ end
a table, also works the same as an array
for i,v in pairs({"A","B"}) do print(v) -- prints A then B print(i) -- prints 1 then 2 end
also if it helps imagine i as index and v as value