What you need to do
So, you're trying to gather all of the SelectionBoxes in workspace and change their color?
For this, you can use recursion. Recursion is essentially re-iterating a function upon itself. Like if you were to go;
function a()
a()
end
This is recursion. But be wary when using recursion, as you can easily end up with a stack overflow. Stack overflow errors happen when you call a function inside itself too many times within a short amount of time, with no yeild. The code above would give you a stack overflow error.
So, to use recursion to your advantage? You need to make a function that iterates through workspace. This can be done through a generic for loop. Check if the current child is a SelectionBox, and if it is recolor it. Then, you can recall the function on itself with each child.
Code
function search(model,color)
local function recurse(m,c)
for _,v in next, m:GetChildren() do
if v:IsA("SelectionBox") then
v.Color3 = color
end
if #v:GetChildren() > 0 then
recurse(v,t)
end
end
end
recurse(model,color)
end
Now you can call the function with the specified arguments.
search(workspace,Color3.new(1,0,0))
1 comment
Wow thanks for this. I don't understand what the ; do though.