Code not working as intended

Yeah, ipairs pulls them in order, so 24 parts numbered 1 to 24. One of the bugs I anticipated was the script pulling the lights in the wrong order (should be numbered Ta01, not Ta1 for this to work correctly), BUT your timing difference is 0.01 seconds, which is less than one heartbeat so I didn’t expect any visible effect.

That 0.01 wait is probably also a problem, as it is shorter than the minimum wait time. Again, we’re talking the difference of 1 frame, so will you even see it?

I wasn’t attempting to fix either of those, when the bigger issue of infinite spawn functions loomed overhead.

Should I try putting the 0.01 seconds to like 0.1?

Update: Just tried, nothing happened.

Not yet… I found the error. I defined the coroutine, but never called it… So change the last line (the end of the coroutine) to include “()” as below.

coroutine.wrap(function()
	wait(lightDelay[i])
	while wait() do		
		Fade_In(v)
		wait(.12)
		Fade_Out(v)
		wait(.12)
	end
end) ()

image
Studio screaming out I need to put an additional end
image

Doing so, will make Studio think () is a Syntax Error.

There should be one more “end” after that coroutine, to end the for loop. Looks like it got lost in transit.

This appears as an error when adding another end.

(Ignore the printed Keycodes, that was to track some previous script error I had, but this has nothing to do with this script so don’t worry).

You are very close!

try


    end)()
end

The “()” must follow the coroutine to actually call it. then you end the for loop.

That one fixed the Syntax Error.
Do I try running the script now?

Yeah, because you have 49 children, something else will be broke. Let’s see if it partially works though

Ok, so I ran the script…
It partially works, but not like expected.

It starts from the left to right, not out to in.

https://gyazo.com/cca6b8676f15682872f9567b00da36d0

Thats the lightDelay issue. Using a formula was the wrong call. I’ll fix that asap.

Alright, I got your private DM.
By then with the 1 to 2 hours you got I am already in bed working up early tomorrow.
We can continue tomorrow about this, if you have the time. :slightly_smiling_face:

Here is the table version. This should have the same values as your original code. :slight_smile:

local lightDelay = {
	["Ta1"] = 0.01, ["Ta24"] = 0.01,
	["Ta2"] = 0.02, ["Ta23"] = 0.02,
	["Ta3"] = 0.03, ["Ta22"] = 0.03,
	["Ta4"] = 0.04, ["Ta21"] = 0.04,
	["Ta5"] = 0.05, ["Ta20"] = 0.05,
	["Ta6"] = 0.06, ["Ta19"] = 0.06,
	["Ta7"] = 0.07, ["Ta18"] = 0.07,
	["Ta8"] = 0.08, ["Ta17"] = 0.08,
	["Ta9"] = 0.09, ["Ta16"] = 0.09,
	["Ta10"] = 0.10, ["Ta15"] = 0.10,
	["Ta11"] = 0.11, ["Ta14"] = 0.11,
	["Ta12"] = 0.12, ["Ta13"] = 0.12,
}

function fader(i, v)
	wait(.01)
	v.Head.Beam.SpotLight.Brightness = 2.5+2.5*i
	v.Head.Lens.Transparency = .75-.25*i
	v.Head.Beam.light.Transparency = NumberSequence.new(.75-.25*i)
end

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
	for i = 1,3 do fader(i, v) end	
end

function Fade_Out(v)
	for i = 3,1,-1 do fader(i,v) end	
	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

for i,v in pairs(game:GetService("Workspace").TaLights:GetChildren()) do 
	if lightDelay[v.Name] then	
		coroutine.wrap(function()
			wait(lightDelay[v.Name])
			while wait() do		
				Fade_In(v)
				wait(.12)
				Fade_Out(v)
				wait(.12)
			end
		end) ()
	end	
end
1 Like