I made a code and it works. The code turned my lights in my building on and off, for the first floor. I have 4 other floors to do. the code is long, I had to rename each file a different name and add a line of code for each part.
Example:
On the first floor there are 91 lights. ( I had to rename each)
In each light there are 3 bulbs with a PoointLight in each one.( I had to rename each)(Light1,Light2..)
Now, on the other floors, I have each light that contains 17 parts in a Model (Light).
I have all 91 Lights in a model (SecondFloorLights,ThirdFloorLights...)
I need a code that will go in and get the 3 parts out of each of the 91 lights in each of the floor folders and when I hit the switch turn them on by setting the Brightness to 15. and turn them on by setting the Brightness by 0.
Here is an small example of the code that I have written.
local ison = false
script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0, 0, 0)
function switch()
if (ison == false) then
ison = true
script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0, 2, 0)
script.Parent.Parent.Parent.Light1.Bulb.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light1.Bulb1.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light1.Bulb2.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light10.Bulb.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light10.Bulb1.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light10.Bulb2.PointLight.Brightness = 15
---there is one group for each of the 91 lights(both on the top and bottom).
else
ison = false
script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0, -2, 0)
script.Parent.Parent.Parent.Light1.Bulb.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light1.Bulb1.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light1.Bulb2.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light10.Bulb.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light10.Bulb1.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light10.Bulb2.PointLight.Brightness = 0
end
end
script.Parent.ClickDetector.MouseClick:connect(switch)
If someone could help me with a shorter script I would love that. ( mine is 772 lines long)LOL...
OK, this is what I have come up with based off of and example, but its not working.
Any suggestion's?
local ison = false
script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0, 0, 0)
function switch()
if (ison == false) then
ison = true
script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0, 2, 0)
else
ison = false
script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0, -2, 0)
end
end
if (ison == true) then
for i,v in pairs(script.Parent.Parent.Parent:GetChildren()) do -- for each Light do:
for j,k in pairs(v:GetChildren()) do -- for each Bulb do:
k.PointLight.Brightness = 15 -- Change the PointLight.Brightness
end
end
else
if (ison == false) then
for i,v in pairs(script.Parent.Parent.Parent:GetChildren()) do -- for each Light do:
for j,k in pairs(v:GetChildren()) do -- for each Bulb do:
k.PointLight.Brightness = 0 -- Change the PointLight.Brightness
end
end
end
script.Parent.ClickDetector.MouseClick:connect(switch)

3 comments
I am still new to Lua, I am teaching myself how to code based off of video's and other peoples code. so any suggestions will help.(examples help more) LoL
How can you down vote and not leave any information? Thats dumb.....
I think it's an okay question and gave it a +1. Though the script is long, it's by no means complicated, and you showed us only what we needed to see instead of the whole thing. However, in the future, please provide what error you encountered.