It's not working because you only check if the door is open once, at the very beginning of the game. What you need to do is send a check whenever a light changes, so the door can react accordingly.
The most efficient way to do this is to send the check whenever your other scripts activate the light (ex. if your script turns the light on when clicked, send the check through the same function). But since you didn't clarify how these lights were activated, we can just check the material itself with GetPropertyChangedSignal("Material")
.
02 | local ActivationLights = game.Workspace.ActivationLights |
03 | local DarklightDoor = script.Parent |
06 | local function updateDoor() |
07 | if ActivationLights.Material = = Enum.Material.Neon then |
08 | DarklightDoor.Transparency = 1 |
13 | ActivationLights:GetPropertyChangedSignal( "Material" ):Connect(updateDoor) |
I'm worried that ActivationLights isn't what you think it is since there should be 5 different lights you're checking. If ActivationLights is a Group/Model with the 5 lights inside it, you must use this code instead:
02 | local ActivationLights = game.Workspace.ActivationLights |
03 | local DarklightDoor = script.Parent |
06 | local function updateDoor() |
10 | local isAllNeon = true |
11 | for _,light in pairs (ActivationLights:GetChildren()) do |
12 | if light.Material ~ = Enum.Material.Neon then |
21 | DarklightDoor.Transparency = 1 |
24 | DarklightDoor.Transparency = 0 |
30 | for _,light in pairs (ActivationLights:GetChildren()) do |
31 | light:GetPropertyChangedSignal( "Material" ):Connect(updateDoor) |