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

Help with a script?

Hi,

I have a slight problem with his script.

Turning on is completely fine, everything turns on but when turning off only LP1 turns off. LP2 to LP12 stay on.

How do you fix this??

LP1 = script.Parent.Parent.SpotLight12.Light.SpotLight
LP2 = script.Parent.Parent.SpotLight11.Light.SpotLight
LP3 = script.Parent.Parent.SpotLight10.Light.SpotLight
LP4 = script.Parent.Parent.SpotLight9.Light.SpotLight
LP5 = script.Parent.Parent.SpotLight8.Light.SpotLight
LP6 = script.Parent.Parent.SpotLight7.Light.SpotLight
LP7 = script.Parent.Parent.SpotLight6.Light.SpotLight
LP8 = script.Parent.Parent.SpotLight5.Light.SpotLight
LP9 = script.Parent.Parent.SpotLight4.Light.SpotLight
LP10 = script.Parent.Parent.SpotLight3.Light.SpotLight
LP11 = script.Parent.Parent.SpotLight2.Light.SpotLight
LP12 = script.Parent.Parent.SpotLight1.Light.SpotLight
btn = script.Parent.ClickDetector

function onClick()
if LP1.Enabled == true and
    LP2.Enabled == true and
    LP3.Enabled == true and
    LP4.Enabled == true and
    LP5.Enabled == true and
    LP6.Enabled == true and
    LP7.Enabled == true and
    LP8.Enabled == true and
    LP9.Enabled == true and
    LP10.Enabled == true and
    LP11.Enabled == true and
    LP12.Enabled == true then do
LP1.Enabled = false and
LP2.Enabled = false and
LP3.Enabled = false and
L4P.Enabled = false and
LP5.Enabled = false and
LP6.Enabled = false and
LP7.Enabled = false and
LP8.Enabled = false and
LP9.Enabled = false and
LP10.Enabled = false and
LP11.Enabled = false and
LP12.Enabled = false and
else
LP1.Enabled = true
LP2.Enabled = true
LP3.Enabled = true
LP4.Enabled = true
LP5.Enabled = true
LP6.Enabled = true
LP7.Enabled = true
LP8.Enabled = true
LP9.Enabled = true
LP10.Enabled = true
LP11.Enabled = true
LP12.Enabled = true
end
end
btn.MouseClick:connect(onClick)



2 answers

✓ Accepted answer
local P = script.Parent.Parent
local LP1 = P.SpotLight12.Light.SpotLight
local LP2 = P.SpotLight11.Light.SpotLight
local LP3 = P.SpotLight10.Light.SpotLight
local LP4 = P.SpotLight9.Light.SpotLight
local LP5 = P.SpotLight8.Light.SpotLight
local LP6 = P.SpotLight7.Light.SpotLight
local LP7 = P.SpotLight6.Light.SpotLight
local LP8 = P.SpotLight5.Light.SpotLight
local LP9 = P.SpotLight4.Light.SpotLight
local LP10 = P.SpotLight3.Light.SpotLight
local LP11 = P.SpotLight2.Light.SpotLight
local LP12 = P.SpotLight1.Light.SpotLight
lp = {LP1, LP2, LP3, LP4, LP5, LP6, LP7, LP8, LP9, LP10, LP11, LP12}
btn = script.Parent.ClickDetector

function onClick()
	for i, v in pairs(lp) do
		v.Enabled = not v.Enabled
	end
end

btn.MouseClick:connect(onClick)

That should do it. The and's were what was messing you up when you were setting the Enabled property. I also condensed the code slightly with some for loops.

2 comments

0

Thank you! Works 100%

0

You're welcome.

LPs =  script.Parent.Parent:GetChildren()

for i,v in pairs(LPs) do

if v.Enabled == true then
   v.Enabled = false
         end
end

1 comment

0

?

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