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

Why won't this script work?

Asked by 10 years ago

I have this script but it does not work.

What needs fixing?

local P = script.Parent.Parent
local LP1 = P.Light12.Light.SpotLight
local LP2 = P.Light11.Light.SpotLight
local LP3 = P.Light10.Light.SpotLight
local LP4 = P.Light9.Light.SpotLight
local LP5 = P.Light8.Light.SpotLight
local LP6 = P.Light7.Light.SpotLight
local LP7 = P.Light6.Light.SpotLight
local LP8 = P.Light5.Light.SpotLight
local LP9 = P.Light4.Light.SpotLight
local LP10 = P.Light3.Light.SpotLight
local LP11 = P.Light2.Light.SpotLight
local LP12 = P.Light1.Light.SpotLight
local LP13 = P.Light13.Light.SpotLight
local LP14 = P.Light14.Light.SpotLight
local LP15 = P.Light15.Light.SpotLight
local LP16 = P.Light16.Light.SpotLight
local LP17 = P.Light17.Light.SpotLight
local LP18 = P.Light18.Light.SpotLight
local LP19 = P.Light19.Light.SpotLight
local LP20 = P.Light20.Light.SpotLight
local LP21 = P.Light21.Light.SpotLight
local LP22 = P.Light22.Light.SpotLight
local LP23 = P.Light23.Light.SpotLight
lp = {LP1, LP2, LP3, LP4, LP5, LP6, LP7, LP8, LP9, LP10, LP11, LP12, LP13, LP14, LP15, LP16, LP17, LP18, LP19, LP20, LP21, LP22, LP23}
btn = script.Parent.ClickDetector

function onClick()
    for i, v in pairs(lp) do
   if v.Brightness == 0 then
      while v.Brightness < 1 do
         v.Brightness = v.Brightness + 0.1
         wait()
      end
   else
      while v.Brightness > 0 do
         v.Brightness = v.Brightness - 0.1
         wait()
      end
 end

    end
end

btn.MouseClick:connect(onClick)

1 answer

Log in to vote
0
Answered by
Lacryma 548 Moderation Voter
10 years ago

The problem with yours is that you are not using coroutines and you never broke the loop. Even so, I'd rather use a for loop for this type of operation.

local P = script.Parent.Parent
local LP1 = P.Light12.Light.SpotLight
local LP2 = P.Light11.Light.SpotLight
local LP3 = P.Light10.Light.SpotLight
local LP4 = P.Light9.Light.SpotLight
local LP5 = P.Light8.Light.SpotLight
local LP6 = P.Light7.Light.SpotLight
local LP7 = P.Light6.Light.SpotLight
local LP8 = P.Light5.Light.SpotLight
local LP9 = P.Light4.Light.SpotLight
local LP10 = P.Light3.Light.SpotLight
local LP11 = P.Light2.Light.SpotLight
local LP12 = P.Light1.Light.SpotLight
local LP13 = P.Light13.Light.SpotLight
local LP14 = P.Light14.Light.SpotLight
local LP15 = P.Light15.Light.SpotLight
local LP16 = P.Light16.Light.SpotLight
local LP17 = P.Light17.Light.SpotLight
local LP18 = P.Light18.Light.SpotLight
local LP19 = P.Light19.Light.SpotLight
local LP20 = P.Light20.Light.SpotLight
local LP21 = P.Light21.Light.SpotLight
local LP22 = P.Light22.Light.SpotLight
local LP23 = P.Light23.Light.SpotLight
lp = {LP1, LP2, LP3, LP4, LP5, LP6, LP7, LP8, LP9, LP10, LP11, LP12, LP13, LP14, LP15, LP16, LP17, LP18, LP19, LP20, LP21, LP22, LP23}
btn = script.Parent.ClickDetector

function onClick()
    for i, v in pairs(lp) do
   if v.Brightness == 0 then
for i = 0,  1,  0.1 do
         v.Brightness = v.Brightness + i
         wait()
      end
   else
      for i = 1,  0,  0.1 do
         v.Brightness = v.Brightness - i
         wait()
      end
      end
 end
end

btn.MouseClick:connect(onClick)

0
Do all the lights need to have the same brightness of 1 to work?? kieranm9090 49 — 10y
0
Still does not work, even with all the brightness the same and everything. kieranm9090 49 — 10y
0
It makes it one automatically, no need to change anything. Also, is there any output? Lacryma 548 — 10y
Ad

Answer this question