Code not working as intended

I’m having an issue.
I optimized my code from 300-500 lines to 61 lines.
One problem, during the loop, each thing repeats after a different one is activated.

In this case:
https://gyazo.com/be0c3ec7fcd4569b59b0ea40634dd768
This is a VERY buggy Fade In Effect which is caused by the optimized code. I can’t find any errors that create that buggy effect. At the end of that GIF, I quickly showed the Fade Out effect (which is an example of HOW it should fade).

Here’s my optimized code.

function Fade_In(v)
	v.Head.Lens.Transparency = _G.EFFECT_DIMMER
	v.Head.Beam.light.Transparency = NumberSequence.new(_G.EFFECT_DIMMER)
	v.Head.Beam.SpotLight.Brightness = _G.EFFECT_DIMMER
	wait(.01)
	v.Head.Beam.SpotLight.Brightness = 5
	v.Head.Lens.Transparency = .5
	v.Head.Beam.light.Transparency = NumberSequence.new(.5)
	wait(.01)
	v.Head.Beam.SpotLight.Brightness = 7.5
	v.Head.Lens.Transparency = .25
	v.Head.Beam.light.Transparency = NumberSequence.new(.25)
	wait(.01)
	v.Head.Beam.SpotLight.Brightness = 10
	v.Head.Lens.Transparency = 0
	v.Head.Beam.light.Transparency = NumberSequence.new(0)
end
function Fade_Out(v)
	v.Head.Beam.SpotLight.Brightness = 10
	v.Head.Lens.Transparency = 0
	v.Head.Beam.light.Transparency = NumberSequence.new(0)
	wait(.01)
	v.Head.Beam.SpotLight.Brightness = 7.5
	v.Head.Lens.Transparency = .25
	v.Head.Beam.light.Transparency = NumberSequence.new(.25)
	wait(.01)
	v.Head.Beam.SpotLight.Brightness = 5
	v.Head.Lens.Transparency = .5
	v.Head.Beam.light.Transparency = NumberSequence.new(.5)
	wait(.01)
	v.Head.Lens.Transparency = _G.EFFECT_DIMMER
	v.Head.Beam.light.Transparency = NumberSequence.new(_G.EFFECT_DIMMER)
	v.Head.Beam.SpotLight.Brightness = _G.EFFECT_DIMMER
end
while wait(0.1) do for i,v in pairs(game:GetService("Workspace").TaLights:GetChildren()) do spawn(function()
			if v.Name == "Ta1" or v.Name == "Ta24" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta2" or v.Name == "Ta23" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta3" or v.Name == "Ta22" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta4" or v.Name == "Ta21" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta5" or v.Name == "Ta20" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta5" or v.Name == "Ta20" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta6" or v.Name == "Ta19" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta7" or v.Name == "Ta18" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta8" or v.Name == "Ta17" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta9" or v.Name == "Ta16" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta10" or v.Name == "Ta15" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta11" or v.Name == "Ta14" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta12" or v.Name == "Ta13" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta1" or v.Name == "Ta24" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta2" or v.Name == "Ta23" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta3" or v.Name == "Ta22" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta4" or v.Name == "Ta21" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta5" or v.Name == "Ta20" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta6" or v.Name == "Ta19" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta7" or v.Name == "Ta18" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta8" or v.Name == "Ta17" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta9" or v.Name == "Ta16" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta10" or v.Name == "Ta15" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta11" or v.Name == "Ta14" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta12" or v.Name == "Ta13" then Fade_Out(v) end wait(0.01) 
		end) end end

Function Fade_Out is not the actual Fade Out effect I showed at the end of the GIF, I only called it like that because at the end of the FadeIn Sequence (which is a Fade Turn On), then FadeOut Sequence (which turn them OFF in a fade way), will be activated.

Help will be VERY appreciated.
(I don’t have my old code but trust me, you don’t want to see that disaster. It has the same functions as this but just shortened down to 61 lines.)

1 Like

What…?

Please word it correctly.

What do you mean by all the v’s will be Ta13 (???)
The V’s are there to get the children of TaLights, otherwise my script wouldn’t work.

while true do wait(0.1) local light = game.workspace.TaLights:GetChildren()
for i = 1, #light do wait()
	local v = light[i]
if v.Name == "Ta1" or v.Name == "Ta24" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta2" or v.Name == "Ta23" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta3" or v.Name == "Ta22" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta4" or v.Name == "Ta21" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta5" or v.Name == "Ta20" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta5" or v.Name == "Ta20" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta6" or v.Name == "Ta19" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta7" or v.Name == "Ta18" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta8" or v.Name == "Ta17" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta9" or v.Name == "Ta16" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta10" or v.Name == "Ta15" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta11" or v.Name == "Ta14" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta12" or v.Name == "Ta13" then Fade_In(v) end wait(0.01)
			if v.Name == "Ta1" or v.Name == "Ta24" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta2" or v.Name == "Ta23" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta3" or v.Name == "Ta22" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta4" or v.Name == "Ta21" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta5" or v.Name == "Ta20" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta6" or v.Name == "Ta19" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta7" or v.Name == "Ta18" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta8" or v.Name == "Ta17" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta9" or v.Name == "Ta16" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta10" or v.Name == "Ta15" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta11" or v.Name == "Ta14" then Fade_Out(v) end wait(0.01)
			if v.Name == "Ta12" or v.Name == "Ta13" then Fade_Out(v) end wait(0.01) 
end end end

This is what happens.

https://gyazo.com/c122a08bea3ce9886943c1a6c5d7bc3d

Local cooldown = true
while true do wait(0.5) if cooldown == true then cooldown = false
   local light = game.workspace.TaLights:GetChildren()
for i = 1, #light do wait()
	local v = light[i]
if v.Name == "Ta2" or v.Name == "Ta23" then Fade_In(v) end 
			if v.Name == "Ta3" or v.Name == "Ta22" then Fade_In(v) end
			if v.Name == "Ta4" or v.Name == "Ta21" then Fade_In(v) end
			if v.Name == "Ta5" or v.Name == "Ta20" then Fade_In(v) end 
			if v.Name == "Ta5" or v.Name == "Ta20" then Fade_In(v) end 
			if v.Name == "Ta6" or v.Name == "Ta19" then Fade_In(v) end
			if v.Name == "Ta7" or v.Name == "Ta18" then Fade_In(v) end 
			if v.Name == "Ta8" or v.Name == "Ta17" then Fade_In(v) end 
			if v.Name == "Ta9" or v.Name == "Ta16" then Fade_In(v) end
			if v.Name == "Ta10" or v.Name == "Ta15" then Fade_In(v) end 
			if v.Name == "Ta11" or v.Name == "Ta14" then Fade_In(v) end 
			if v.Name == "Ta12" or v.Name == "Ta13" then Fade_In(v) end 
			if v.Name == "Ta1" or v.Name == "Ta24" then Fade_Out(v) end 
			if v.Name == "Ta2" or v.Name == "Ta23" then Fade_Out(v) end 
			if v.Name == "Ta3" or v.Name == "Ta22" then Fade_Out(v) end 
			if v.Name == "Ta4" or v.Name == "Ta21" then Fade_Out(v) end 
			if v.Name == "Ta5" or v.Name == "Ta20" then Fade_Out(v) end 
			if v.Name == "Ta6" or v.Name == "Ta19" then Fade_Out(v) end 
			if v.Name == "Ta7" or v.Name == "Ta18" then Fade_Out(v) end 
			if v.Name == "Ta8" or v.Name == "Ta17" then Fade_Out(v) end
			if v.Name == "Ta9" or v.Name == "Ta16" then Fade_Out(v) end 
			if v.Name == "Ta10" or v.Name == "Ta15" then Fade_Out(v) end
			if v.Name == "Ta11" or v.Name == "Ta14" then Fade_Out(v) end 
			if v.Name == "Ta12" or v.Name == "Ta13" then Fade_Out(v) end
end 
cooldown = true
end end

image
image

nvm iwill just fix it so fast recopy the script

At this point, it’s just like a wait(math.random() function.
https://gyazo.com/b884823e442621b5c947a6598e809964

if you want them all light at ones you have to use remote even that active them from script inside them that active them after remote even active

looks like the server lagy the script must work fine and faster

It’s not the server by the way.
It’s the script generally.
Any other script works just fine.

It’s supposed to light them all, then turn them all off, with different activation times?

try puplic the game and play it on roblox maybe it will work fine

Exactly.

For example.

One Moving Head turns on, the next one as well, but in this case all the beams turn from out to in.

It’s not… the server… it’s the script.

OK, you need 2 loops. One to turn them all on, one to turn them all off. You are in fact turning them on and off before moving on.

ithink he want to turn them on then off

How would I use 2 loops, I am pretty sure, once there’s one loop inside the script, anything after the loop won’t run… right?

I’ll demonstrate, but it will take a few minutes to optimize this enough to edit it.

Alright, you can take the original script in post #1 to optimize it.

If the old code is needed, I’ll try to re-build it quickly.