Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make a door that opens when five lights are activated or neon?

-- Variables
local ActivationLights = game.Workspace.ActivationLights
local DarklightDoor = script.Parent

local function updateDoor()

    local isAllNeon = true
    for _,light in pairs(ActivationLights:GetChildren()) do
        if light.Material ~= Enum.Material.Neon then
            isAllNeon = false
            break
        end
    end

    if isAllNeon then
        DarklightDoor.Transparency = 1
        DarklightDoor.CanCollide = false
    else

    end

end

for _,light in pairs(ActivationLights:GetChildren()) do
    light:GetPropertyChangedSignal("Material"):Connect(updateDoor)
end

Anyways, here is an example of what I'm trying to do. I want the door to become transparent and CanCollide = false when ErnestaLight, DanLight, AquiziviteLIght, LovelyLight, and QuinnKennithLight are neon/activated. Please help! (For a myth game) Before you ask, nothing is underlined, nothing comes out in the output.

2 comments

0

Didn't you already ask this?

0

Yes, I’ve been trying to get an answer and have been working to find the right code, but I cant.

2 answers

--variables for your lights and door here


local lights = {light1, light2, light3, light4, light5,}

local function Evaluate()
	local doorOpen = true
	 for i = 1, #lights do
	        if not lights[i].Material == Enum.Material.Neon then
	            doorOpen = false
	            break
	        end
	    end

	if doorOpen then
	YourDoor.Cancollide = false
	YourDoor.Transparency = .5 -- or whatever you prefer

	else 
	YourDoor.CanCollide = true
	YourDoor.Tansparency = 0

	 end
end

for i = 1, #lights do
    lights[i].Changed:Connect(function()
       Evaluate()
print ("Triggered") -- this was a test, delete it if you like
    end)
end


2 comments

0

This is the script I made for a similar case in my game, declare your lights and door at the top of the script. It should 'open' your door if ALL five lights are neon

0

Look at my answer below

--variables for your lights and door here

local lights = {game.Workspace.DarklightDoor.AquiziviteLight, game.Workspace.DarklightDoor.DanLight, game.Workspace.DarklightDoor.ErnestaLight, game.Workspace.DarklightDoor.LovelyLight, game.Workspace.DarklightDoor.QuinnKennithLight} local YourDoor = game.Workspace.DarklightDoor

local function Evaluate() local doorOpen = true for i = 1, #lights do if not lights[i].Material == Enum.Material.Neon then doorOpen = false break end end

if doorOpen then
YourDoor.CanCollide = false
YourDoor.Transparency = 1 -- or whatever you prefer

 end

end

for i = 1, #lights do lights[i].Changed:Connect(function() Evaluate() print ("Triggered") -- this was a test, delete it if you like end) end

I changed it to this, why isn't it working?

1 comment

0

not 100% sure. try local light1 = game.Workspace.DarklightDoor.AquiziviteLight, light2 = .... , .... then your table local lights = {light1, light2, light3, light4, light5,}

This discussion is preserved as it was. New answers, comments, and votes are closed.