Need help with a for loop

My for loop isn’t working.

It only enables the particles, not the light.
Also, nothing disables when I try.

Script:

repStore.SpellEvents.FlameRitual.OnServerEvent:Connect(function()
	if game.Workspace.Altar.IsActive.Value == true then
		for _,l in pairs(game.Workspace.Flames:GetChildren()) do
			if l:IsA("ParticleEmitter") then
				l.Enabled = true
			if l:IsA("SurfaceLight") then
				l.Enabled = true
					wait(5)
				l.Enabled = false						
				end
			end
		end
	end
end)

local script:

	elseif string.find(msg:lower(),"flammare") ~= nil and debounce == false then
		debounce = true
		event3:FireServer()
		wait(5)
		debounce = false
	end
end)

There is more to the scripts, these are just parts that I am having the issue with

try this

repStore.SpellEvents.FlameRitual.OnServerEvent:Connect(function()
	if game.Workspace.Altar.IsActive.Value == true then
		for _,l in pairs(game.Workspace.Flames:GetChildren()) do
			if l:IsA("ParticleEmitter") then
				l.Enabled = true
			elseif l:IsA("SurfaceLight") then
				l.Enabled = true
					wait(5)
				l.Enabled = false						
			end
		end
	end
end)

I tried this before and it didn’t work.

Lights didn’t enable, nothing disabled.

I just saw that I made a mistake there is an extra end, did you think to remove it when you tested?

Yes. When I changed it to elseif, I removed the extra end.

Are your “ParticleEmiter” and your “Surface light” in part?

Yes. There is 2 particle emitters and 1 surface light
image

Have you tried adding a print after the if statement?

repStore.SpellEvents.FlameRitual.OnServerEvent:Connect(function()
	if game.Workspace.Altar.IsActive.Value == true then
		for _,l in pairs(game.Workspace.Flames:GetChildren()) do
			if l:IsA("ParticleEmitter") then
				l.Enabled = true
			elseif l:IsA("SurfaceLight") then
print("Surface light found!")
				l.Enabled = true
					wait(5)
				l.Enabled = false						
			end
		end
	end
end)

this is just to see if it even passes the if statement

Using “elseif” will not work at all since the 1st if statement is true therefore the elseif statement will not run

No, it will loop for all parts(3 times)
1 of them is not a paritcle emitter therefore it will work

the loop verifies each child of the part so when it passes on a “Surface Ligth” the first if will be false

Just added this, it printed “Surface light found!”

The surface light came on, but still nothing goes off.

explain exactly how it will not work? if its already enabled it will just enable it again, not break the script?

No i was saying that it will pass the elseif statement

um.

it enabled the surface light, but it still doesn’t turn off. nothing does.

although that may be true nothing will go wrong if it returns false using elseif makes it no different

I just tested the script and for me it works, it’s just that the lights don’t show much

if it doesnt turn off turn its brightness to 0 perhaps, although it should

I also tried to recreate the issue but it works fine according to my prints.
I noticed the particle emitters won’t disable so this is an updated script:

repStore.SpellEvents.FlameRitual.OnServerEvent:Connect(function()
	if game.Workspace.Altar.IsActive.Value == true then
		for _,l in pairs(game.Workspace.Flames:GetChildren()) do
			if l:IsA("ParticleEmitter") then
				l.Enabled = true
                wait(5)
                l.Enabled = false
			elseif l:IsA("SurfaceLight") then
print("Surface light found!")
				l.Enabled = true
					wait(5)
				l.Enabled = false						
			end
		end
	end
end)

https://gyazo.com/712ac45dff5798f47de0dbbea9dc0dc3 I think it’s just the ligth

1 Like