How could I search for the Value IsOn in all folders available.
Basically to elaborate what im attempting to do:
Have a main breaker switch which turns off all the lights in the building, so search each lighting ‘zone’ or folder for the IsOn value, and then if it finds it, set it to 0 (it’s a 1 and 0 system as it has multiple states than 1 or 0)
Use a for loop and GetChildren to iterate the children of the “Lighting” folder, check if the child is a folder with IsA (or ClassName), use FindFirstChild on the child folder to check if it has a child named “IsOn”, if it does then set the value
You could just create a table with all the values in the folder, then you can loop through them, and get their values.
An Example
local folder = * -- the folder we are searching from
local switches = {} -- the list every boolen value in the folder is stored in
for index, object in pairs(folder:GetDescendants()) do
if object and object:IsA("BoolValue") then
table.insert(switches, object) -- add every boolen value to the list
end
end
function on()
for _, child in pairs(script.Parent:GetChildren()) do
if child:IsA("Folder") then
local zones = child:FindFirstChild("IsOn")
zones.IsOn.Value = 1
end
end
end
However this results in the error: IsOn is not a valid member of Folder "Workspace.BuildingSystems.Lighting"
function on()
for _, child in pairs(script.Parent:GetChildren()) do
if child:IsA("Folder") then
local zones = child:FindFirstChild("IsOn")
-- // Check if "IsOn" exist.
if zones then
zones.Value = 1
end
end
end
end
IsOn is not a valid member of Folder “Workspace.BuildingSystems.Lighting”
function on()
for _, child in pairs(script.Parent:GetChildren()) do
if child:IsA("Folder") then
local zones = child:FindFirstChild("IsOn")
if zones then
zones.IsOn.Value = 1
end
end
end
end
function on()
for _, child in pairs(script.Parent.Parent:GetChildren()) do
if child:IsA("Folder") then
local zones = child:FindFirstChild("IsOn")
if zones then
zones.Value = 1
end
end
end
end