Need help on making a script that detects particle enabled then turn on lights

Hello, as the topic says, im trying to make a script that detects particle enabled then turn on lights
I have a folder that contains multiple models that has a particle emitter and lights on each of them. what i want is a script that sits inside the folder that controls their lights.
Screenshot 2023-06-03 124316
Like in this screenshot, when “Water” is enabled, the script will enabled these light in a halogen light like way (unlike leds, halogen has a slight dimming/fade when turning on or off) inside the “bulb”.
^ What i meant by halogen way are just like in this video of dubai fountain’s halogen lights: 171003 Dubai - Burj Fountain Video - YouTube

And when water is disabled, turn off the light.
Screenshot 2023-06-03 124632

I tried using while true do with for i,v in pairs script that were inside each model, but it is taking a lot of resources as there were hundreds of them. and because I’m still new to studio (1 year, still haven’t learn much) I might not have tried other methods that might work

1 Like

use part.Changed function to detect whether the properties of the particles have changed

I would use the CollectionService to tag all the Mini00 models that contain the lights and main models. Here is an api reference:

I would then use a single script to retrieve all the tagged instances through the CollectionService and check for the PropertyChanged signal of the water ParticleEmitter to check when it is enabled and to turn on the lights when it is and off when not. Here is a code example taking into consideration that you tagged the Mini00 models as “Tagged”:

local CLS = game:GetService("CollectionService")

for _, mini00 in ipairs(CLS:GetTagged("Tagged")) do
   local lights = mini00.lights
   local water = mini00.main.noz.Water

   water:GetPropertyChangedSignal("Enabled"):Connect(function()
      for _, bulb in ipairs(lights:GetChildren()) do
         bulb.light.Enabled = water.Enabled
      end
   end)
end
1 Like

But what if they’re named
“Mini00”, “Mini01”, "Mini02, etc?
^I forgot to mention this, but yeah they’re named like that in the folder.

Here is a simple script to do what you want with modified code of @Scripter_Joe , try running the script, but note that I am unable to test it as I don’t have access to your work. Anyways, I want to remind you that I didn’t write this script in a studio environment, so there’s a possibility that it may not work as intended. Let me know if it’s not worked as intented. If i fixed the issue please make sure to close your support topic by check the solution.

You can also like to support :cool:

Script

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

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

	local lights = Path[Names].lights
	local water = Path[Names].main.noz.Water

	water:GetPropertyChangedSignal("Enabled"):Connect(function()
		for _, bulb in ipairs(lights:GetChildren()) do
			bulb.light.Enabled = water.Enabled
		end
	end)
end

Test place
//

~ @hollaquetalBRUH

1 Like

Hello Sarah, I decided to change their Name to have three digits instead since there are 103 of them. (Sorry about this change this could be a bit of a burden)
^ And with “Mini00”, which should be “Mini000”, I changed it to start with “Mini001” instead as yeah, simplifying it.
Would this be correct? (I tried this modified one below, doesn’t work oof)

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

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

	local lights = Path[Names].lights
	local water = Path[Names].main.noz.Water

	water:GetPropertyChangedSignal("Enabled"):Connect(function()
		for _, bulb in ipairs(lights:GetChildren()) do
			bulb.light.Enabled = water.Enabled
		end
	end)
end

I tested your script on a small scale on another baseplate and it works! But is it possible to make the lights turning off slowly? Example, as soon as water got disabled, wait 2 seconds then turn the brightness slowly til it reaches 0 and then disable it.

Update on this message, to disable the lights (2 seconds then turn the brightness slowly til it reaches 0 and then disable it.) By detecting “Refill” (has the same parent as Water) is enabled

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.