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

Is there anyway to make this script 'smaller'?

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

✓ Accepted answer

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!

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