Code not working as intended

There’s no print(“Hello World”) in the script though.

The instances also don’t delete because I’ve checked it before, while running the game.

Just add the line. It doesn’t add or harm anything. You are looking for a new bug.

If you can establish that the code does not run, the problem exists outside the code and we can stop looking there,

Ok, stupid me put the Looptest function in the wrong line.

I managed to print out the amount of Instances
image
Because I instead thought of the for loops inside of function Fade_Out/In(v)

Although it prints out the children, but the actual script does not run (Fade In effect).

EDIT: After the printing, the code stops.

ok, that means the problem is my loop :smiley: I will remove the lighting part of the code and see what I messed up.

BTW 49 children? That means you have things in there that are not lights. I was assuming that the folder only had the 24 lights. My formula for lightdelay will not work. That’s fixable, but the loop needs to run first.

Oh… yeah… 49 children, why? I duplicated the 24 instances (1 of them I accidentally dupliacted 2 times so making that 49 instead of 48) because this system allows you to add as many instances (basically that’s why the GetChildren() part is there), you want, as long as they have the name ranging from Ta1 to Ta24.
If that was not the case, my Handler for the beams and the actual Panel where I store all the effect wouldn’t work.

I think I follow that. It just means LightDelay has to use the table, not a formula. I intended the table for customizing the delay, but it serves a higher purpose now.

So in that case, we could add somewhere, something like this, where it gets all childrens that are named Ta with their numbers?

for i,v in pairs(game:GetService("Workspace").TaLights:GetChildren()) do 
	local num = tonumber(v.Name:match("Ta(%d+)"))
		if num then
            -- code here
		end
	end

Because what I’m thinking is the line

if i <= 12 then

is only looking for half of the instances and not names?

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