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

Can someone help me with this switch?

Asked by 9 years ago

OK! I got this script to work right, but if anyone know a shorter way can you let me know please. I have 4 more floors the same size to do..in detail please im new to this LUA.... thanks

This script works but stops at Light15 and don't run anything after that why? the only lights to turn off and on are Light1,Light10,Light11,Light12,Light13,Light14, and Light15. The rest don't do anything they don't change.

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

script.Parent.Parent.Parent.Light11.Bulb.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light11.Bulb1.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light11.Bulb2.PointLight.Brightness = 15

script.Parent.Parent.Parent.Light12.Bulb.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light12.Bulb1.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light12.Bulb2.PointLight.Brightness = 15

script.Parent.Parent.Parent.Light13.Bulb.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light13.Bulb1.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light13.Bulb2.PointLight.Brightness = 15

script.Parent.Parent.Parent.Light14.Bulb.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light14.Bulb1.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light14.Bulb2.PointLight.Brightness = 15

script.Parent.Parent.Parent.Light15.Bulb.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light15.Bulb1.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light15.Bulb2.PointLight.Brightness = 15

script.Parent.Parent.Parent.Light16.Bulb.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light16.Bulb1.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light16.Bulb2.PointLight.Brightness = 15

script.Parent.Parent.Parent.Light17.Bulb.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light17.Bulb1.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light17.Bulb2.PointLight.Brightness = 15

script.Parent.Parent.Parent.Light18.Bulb.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light18.Bulb1.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light18.Bulb2.PointLight.Brightness = 15

script.Parent.Parent.Parent.Light19.Bulb.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light19.Bulb1.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light19.Bulb2.PointLight.Brightness = 15

script.Parent.Parent.Parent.Light2.Bulb.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light2.Bulb1.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light2.Bulb2.PointLight.Brightness = 15

script.Parent.Parent.Parent.Light20.Bulb.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light20.Bulb1.PointLight.Brightness = 15
script.Parent.Parent.Parent.Light20.Bulb2.PointLight.Brightness = 15

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

script.Parent.Parent.Parent.Light11.Bulb.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light11.Bulb1.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light11.Bulb2.PointLight.Brightness = 0

script.Parent.Parent.Parent.Light12.Bulb.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light12.Bulb1.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light12.Bulb2.PointLight.Brightness = 0

script.Parent.Parent.Parent.Light13.Bulb.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light13.Bulb1.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light13.Bulb2.PointLight.Brightness = 0

script.Parent.Parent.Parent.Light14.Bulb.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light14.Bulb1.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light14.Bulb2.PointLight.Brightness = 0

script.Parent.Parent.Parent.Light15.Bulb.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light15.Bulb1.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light15.Bulb2.PointLight.Brightness = 0

script.Parent.Parent.Parent.Light16.Bulb.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light16.Bulb1.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light16.Bulb2.PointLight.Brightness = 0

script.Parent.Parent.Parent.Light17.Bulb.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light17.Bulb1.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light17.Bulb2.PointLight.Brightness = 0

script.Parent.Parent.Parent.Light18.Bulb.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light18.Bulb1.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light18.Bulb2.PointLight.Brightness = 0

script.Parent.Parent.Parent.Light19.Bulb.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light19.Bulb1.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light19.Bulb2.PointLight.Brightness = 0

script.Parent.Parent.Parent.Light2.Bulb.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light2.Bulb1.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light2.Bulb2.PointLight.Brightness = 0

script.Parent.Parent.Parent.Light20.Bulb.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light20.Bulb1.PointLight.Brightness = 0
script.Parent.Parent.Parent.Light20.Bulb2.PointLight.Brightness = 0


end
end

1 answer

Log in to vote
2
Answered by 9 years ago

Sorry but why not making a loop? You cannot write a 118's row-long code for just a little amount of models! Do you know why this doesn't work? Because you have a 118's row-long code and you cannot figure out the problem inside everything! Make a loop and it will be all good and EASIER, like this:

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 Buld do:
        k.PointLight.Brightness = yourvaluehere -- Change the PointLight.Brightness
    end
end

This means that you pass every "Bulb" in every "Light" and then change the PointLight.Brightness in just 1 row...

0
i dont understand , i have been looking at this and i put it in ther instead of my line code and it isnt working can you put some details on how to put it in my code please. snipers007 0 — 9y
0
it's just like a normal script, put that in the script and instead of "yourvaluehere" put your number like "1" or "15, repeat the code for every value you need! alessandro112 161 — 9y
Ad

Answer this question