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

How do I phrase a For i, v statement to go through children of a folder?

Asked by 3 years ago

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.

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.

end

Thank you in advance!

1 answer

Log in to vote
0
Answered by 3 years ago

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

for i,v in ipairs(Folder:GetChildren()) do -- or descendants also ipairs or pairs
    if v:IsA("BasePart") then
        v.BrickColor = BrickColor.new()
    end
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

Ad

Answer this question