How would I make this part detect if a light changed

Hello there users of devforum. I have this Tesla gate thats suppose to activate when all lights in the game change to a specific color, say 255,1,1. In general this tesla gate is supposed to start a function whenever it detects all point lights changing color.

I have tried to use the script GetPropertyChangedSignal but then so it doesn’t work.
Any Ideas? Also the script is unfinished because I didn’t know what else to put in it.

local Tesla = script.Parent.Parent.TeslaGate

Tesla.Transparency =  1
Tesla.CanCollide = false

local descendants = game.Workspace:GetDescendants()
for index, descendants in pairs(descendants) do
	if descendants:IsA("PointLight") then
		descendants.
	end
end
		

Well if it’s meant to activate at the same time something else activates. Why can’t you just put it under the code which changes the lights, to also open the gate?

1 Like

Never thought of that. I’ll try it

1 Like

It runs the code before the lights can even change colors.

image

This is a seperate code that changes all the lights. Theres more to it but I feel this is the important part

button.MouseClick:Connect(function()
	if not AlarmIsOn  then
		AlarmIsOn = true
		for index, descendants in pairs(descendants) do
			if descendants:IsA("PointLight") then
				descendants.Color = Color3.fromRGB(255,1,1)
				HighAlarm:Play()
			end
		end

You would probably want it to be underneath the for loop so it runs after all the lights have changed.
You can also put a task.wait() if you want a small delay.

Like this?

image

Because this is what happened

Could you show us your script for when you used this? Maybe it had an error.

No, underneath the for loop, you are putting it inside the for loop.

for index, descendants in descendants do
	--lights change here
end
print('Tesla Changed') --runs after the loop with lights changing

image

Aha, error. Try this.

descendants:GetPropertyChangedSignal("Color"):Connect(function()
    Tesla.Transparency = 0.3
end)
1 Like

image

Mind showing the code too when you change it?

This worked.
image

I do not recommend this solution as the same code will run for every light that’s being changed. Meaning if there’s 100 lights it’ll set the transparency a 100 times, when it could just instead do it once.

That’s what the user was wanting accodring to their code, that’s what I supplied.

I was attempting to have them put it inside the code which already changes the lights, so there’s no double work for the same task.

You could also add a timed debounce, or even disconnect the event if needed that badly.

That’s not stopping it from running it 99 times more than neccessary the first time if there’s 100 changing lights. :confused:

Just said, you can add a timed debounce.