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 8 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?

while true do
    wait()
    if game.Workspace.LightsMode1.Mode.Value == 2 then
        game.Workspace.LightSet1.Lights.Light1.Transparency = 0.7
        game.Workspace.LightSet1.Lights.Light1.SpotLight.Enabled = false
        wait(0.2)
        game.Workspace.LightSet1.Lights.Light2.Transparency = 0.7
        game.Workspace.LightSet1.Lights.Light2.SpotLight.Enabled = false
        wait(0.2)
        game.Workspace.LightSet1.Lights.Light3.Transparency = 0.7
        game.Workspace.LightSet1.Lights.Light3.SpotLight.Enabled = false
        wait(0.2)
        game.Workspace.LightSet1.Lights.Light4.Transparency = 0.7
        game.Workspace.LightSet1.Lights.Light4.SpotLight.Enabled = false
        wait(0.2)
        game.Workspace.LightSet1.Lights.Light5.Transparency = 0.7
        game.Workspace.LightSet1.Lights.Light5.SpotLight.Enabled = false
    end
end

1 answer

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

You can use for loop to do that.

number = ??? --insert total number of lights here

while true do
    wait()
    if game.Workspace.LightsMode1.Mode.Value == 2 then
        for i = 1,number do
        game.Workspace.LightSet1.Lights["Light" .. i].Transparency = 0.7
        game.Workspace.LightSet1.Lights["Light" .. i].SpotLight.Enabled = false
        wait(0.2)
    end
    end
end

I hope this helped you!

Ad

Answer this question