Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a door that is opened when 5 lights are activated?

Asked by
Qu_xtty -8
5 years ago

I'm trying to make a door that opens when five lights are activated. I don't see what I'm doing wrong. Here is my script:

local DarklightDoor = script.Parent if game.Workspace.ActivationLights.Material == Enum.Material.Neon then Transparency = 1 end

0
try a "while loop" ~~~~~~~~~~~~~~~~ local DarklightDoor = script.Parent while true do wait() if workspace.AcvtivationLights.Material == Enum.Material.Neon then Transparency = 1 end end ~~~~~~~~~~~~~~~~~~~~~~ ScriptsALot 91 — 5y
0
Sorry, while loop doesn't work, let me know if you can figure anything else out@ Qu_xtty -8 — 5y

2 answers

Log in to vote
0
Answered by
Borrahh 265 Moderation Voter
5 years ago

You can do this

01light1On = false
02light2On = false
03light3On = false
04light4On = false
05light5On = false
06 
07 
08--However you are going to make them to turn on, goes here
09 
10if light1On == true and light2On == true and light3On == true and light4On == true and light5On == true then
11-- Code goes here to open the door
12end)
0
This doesn't work, I just tested it. Qu_xtty -8 — 5y
0
It doesn't work because all light variables are set to false as default and are never changed. I advice you to learn how to program before making questions which can't be answered without scripting all the code for you. User#27525 1 — 5y
0
^^^ Agreed, if you can't make a simple value changing script, you require more practice and aren't ready to ask questions without us having to build the whole if not most of the script for you. HSlightsteel 14 — 5y
0
Well Yes My script doesn't "work" because you haven't turned the variables back on, i can't do everything for you, use your logic, and you will make it! Borrahh 265 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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").

01--set up variables for the objects
02local ActivationLights = game.Workspace.ActivationLights
03local DarklightDoor = script.Parent
04 
05--handles updating the door to open/closed depending on the lights' material
06local function updateDoor()
07    if ActivationLights.Material == Enum.Material.Neon then
08        DarklightDoor.Transparency = 1
09    end
10end
11 
12--connects the lights' material changing to the door's update
13ActivationLights: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:

01--set up variables for the objects
02local ActivationLights = game.Workspace.ActivationLights
03local DarklightDoor = script.Parent
04 
05--handles updating the door to open/closed depending on the lights' material
06local function updateDoor()
07 
08    --loops through all the lights and checks their materials
09    --isAllNeon is default to true, but turns false after seeing one light if it sees a light that's not neon
10    local isAllNeon = true
11    for _,light in pairs(ActivationLights:GetChildren()) do
12        if light.Material ~= Enum.Material.Neon then
13            isAllNeon = false
14            break
15        end
View all 32 lines...
0
I didn't want it to close, so I removed the closed option, but when I had it it still didn't work. Please help! Qu_xtty -8 — 5y

Answer this question