Trying to fix lights' "Dimming Effect"

I want to make the lights to have dimming effects, but because that this is a loop command, it actually loops the “dimming” too, causing some kind of seizure effects, any alternatives?
^ Dimming effect, as if the halogen lights that were used at the Dubai Fountain.

local MinIndex = 1
local MaxIndex = 84 -- MODIFY to the max number exemple here Mini17 the 17
local CurrentIn = 0
local Path = game.Workspace.Minis.Ring4


for current = MinIndex, MaxIndex do
	CurrentIn = CurrentIn + 1
	local Names = "Mini000"
	if CurrentIn < 10 then
		Names = "Mini00"..CurrentIn
	else
		Names = "Mini0"..CurrentIn
	end

	local lights = Path[Names].lights
	local water = Path[Names].Main.Nozzle.Water
	local refill = Path[Names].Main.Nozzle.Refill

	water:GetPropertyChangedSignal("Enabled"):Connect(function()
		for _, bulb in ipairs(lights:GetChildren()) do
			bulb.light.Brightness = 0
			bulb.light.Enabled = true
			bulb.Material = "Neon"
		end
		task.wait(.2)
		for _, bulb in ipairs(lights:GetChildren()) do
			bulb.light.Brightness = .1
		end
		task.wait(.2)
		for _, bulb in ipairs(lights:GetChildren()) do
			bulb.light.Brightness = .3
		end
		task.wait(.2)
		for _, bulb in ipairs(lights:GetChildren()) do
			bulb.light.Brightness = .5
		end
		task.wait(.2)
		for _, bulb in ipairs(lights:GetChildren()) do
			bulb.light.Brightness = .7
		end
		task.wait(.2)
		for _, bulb in ipairs(lights:GetChildren()) do
			bulb.light.Brightness = 1
		end
	end)
	refill:GetPropertyChangedSignal("Enabled"):Connect(function()
		for _, bulb in ipairs(lights:GetChildren()) do
			bulb.light.Brightness = 1
		end
		task.wait(.2)
		for _, bulb in ipairs(lights:GetChildren()) do
			bulb.light.Brightness = .7
		end
		task.wait(.2)
		for _, bulb in ipairs(lights:GetChildren()) do
			bulb.light.Brightness = .5
		end
		task.wait(.2)
		for _, bulb in ipairs(lights:GetChildren()) do
			bulb.light.Brightness = .3
		end
		task.wait(.2)
		for _, bulb in ipairs(lights:GetChildren()) do
			bulb.light.Brightness = .1
		end
		task.wait(.2)
		for _, bulb in ipairs(lights:GetChildren()) do
			bulb.light.Enabled = false
			bulb.Material = "Glass"
		end
	end)
end

image

Hi there, the code is definitely flawed due to the 6 iterations you are performing over the lights. I can’t help to fix it though unless you explain more clearly how these functions are being fired (i.e. how are you changing the properties these functions connect to?).

2 Likes

I am a bit confused here, I know incandescent lights like you want to simulate turn down quickly and lower light color, are you trying to dim them as if you turned it off?

Here’s how it works
the script are located inside a folder together with these models called “Minis###”.
Inside these models there are
“Main.Nozzle.Water”
“Main.Nozzle.Refill”
“lights.bulb.light” (4 of them)
On another folder, there’s a button inside a surfacegui that Enables “Water” for .7 second then disable it
^ after 3 seconds of that happening, Refill will be enabled and turn off after .3 second.

What i tried is that i want to well, trying the dimming effect i mentioned (just like the the halogens at dubai fountain, 171003 Dubai - Burj Fountain Video - YouTube).
The Lights would slowly getting brighter when Water’s enabled till it reaches the brightness of 1. Once refill has been enabled, it will slowly getting dimmer till it reaches 0.

Hopefully anyone could help since I had to delay my updates :skull:

And I’m still learning lua by myself so whatever I’m doing could be very wrong and inefficient so it’ll be lovely if anyone can help :>

I think what definitely is your issue is the absolute ludicrous amounts of times youre having to iterate through something so loosley defined, I think if you were to run GetChildren() and run a IsA(“Spotlight”) and temporarily assign those light instances to seperate variables and set those property values to another number variable that can be simply changed and would eliminate the use of having to index through the same model 11 more times.