Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why won't this script work?

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

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)

3 comments

0

Do all the lights need to have the same brightness of 1 to work??

0

Still does not work, even with all the brightness the same and everything.

0

It makes it one automatically, no need to change anything. Also, is there any output?

This discussion is preserved as it was. New answers, comments, and votes are closed.