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

Is there anyway to make this script 'smaller'?

Asked by 9 years ago

I was wondering if I could neaten up/make this script shorter? The script I have pasted in is only some of it, the rest continues on, Light6, 7, 8 etc. I also would like it in the same order, so Light1 starts first, I was just wondering if anyone knows how to make this script shorter?

01while true do
02    wait()
03    if game.Workspace.LightsMode1.Mode.Value == 2 then
04        game.Workspace.LightSet1.Lights.Light1.Transparency = 0.7
05        game.Workspace.LightSet1.Lights.Light1.SpotLight.Enabled = false
06        wait(0.2)
07        game.Workspace.LightSet1.Lights.Light2.Transparency = 0.7
08        game.Workspace.LightSet1.Lights.Light2.SpotLight.Enabled = false
09        wait(0.2)
10        game.Workspace.LightSet1.Lights.Light3.Transparency = 0.7
11        game.Workspace.LightSet1.Lights.Light3.SpotLight.Enabled = false
12        wait(0.2)
13        game.Workspace.LightSet1.Lights.Light4.Transparency = 0.7
14        game.Workspace.LightSet1.Lights.Light4.SpotLight.Enabled = false
15        wait(0.2)
16        game.Workspace.LightSet1.Lights.Light5.Transparency = 0.7
17        game.Workspace.LightSet1.Lights.Light5.SpotLight.Enabled = false
18    end
19end

1 answer

Log in to vote
1
Answered by
Mokiros 135
9 years ago

You can use for loop to do that.

01number = ??? --insert total number of lights here
02 
03while true do
04    wait()
05    if game.Workspace.LightsMode1.Mode.Value == 2 then
06        for i = 1,number do
07        game.Workspace.LightSet1.Lights["Light" .. i].Transparency = 0.7
08        game.Workspace.LightSet1.Lights["Light" .. i].SpotLight.Enabled = false
09        wait(0.2)
10    end
11    end
12end

I hope this helped you!

Ad

Answer this question