Okay here is a random script a wrote a while ago
local floor = script.Parent
wait(10)
for i, v in floor:GetDescendants() do
if v:IsA("ProximityPrompt") then
v.Triggered:Connect(function()
if v.Name == "HallPrompt" then
-- the door
local prox = v
local green = prox.Parent.Parent.Green
local red = prox.Parent.Parent.Red
local Storage = prox.Parent.Parent.Parent
local In = Storage.Orange.In.Union
local Out = Storage.Orange.Out.Union
local rollup = Storage.Orange.RollUp
local update = Storage.oclosed
wait(0.2)
if In.Transparency == 0 then
green.Material = "Neon" -- door opened
green.Color = Color3.fromRGB(33, 243, 22)
green.Massless = false
red.Material = "Glass"
red.Color = Color3.fromRGB(153, 0, 74)
In.Transparency = 1
In.CanCollide = false
Out.Transparency = 1
Out.CanCollide = false
prox.ObjectText = "Status: Open"
rollup.Transparency = 0
update.TextScaled = true
In.creak:Play()
else
green.Material = "Glass" -- door closed
green.Color = Color3.fromRGB(0, 138, 99)
green.Massless = true
red.Material = "Neon"
red.Color = Color3.fromRGB(186, 64, 8)
In.Transparency = 0
In.CanCollide = true
Out.Transparency = 0
Out.CanCollide = true
prox.ObjectText = "Status: Closed"
rollup.Transparency = 1
update.TextScaled = false
In.bang:Play()
end
-- the arrows
local useprox = v.Parent.HallPrompt
local Storage = useprox.Parent.Parent.Parent
local needs = Storage["Inside Toggle"]
local flat = needs.Flat
local prox = flat.InsidePrompt
local green = needs.Green
local red = needs.Red
local In = Storage.Orange.In.Union
wait(0.5)
if In.Transparency == 1 then
green.Material = "Neon" -- door opened
green.Color = Color3.fromRGB(33, 243, 22)
green.Massless = false
red.Material = "Glass"
red.Color = Color3.fromRGB(153, 0, 74)
prox.ObjectText = "Status: Open"
else
if In.Transparency == 0 then
green.Material = "Glass" -- door closed
green.Color = Color3.fromRGB(0, 138, 99)
green.Massless = true
red.Material = "Neon"
red.Color = Color3.fromRGB(186, 64, 8)
prox.ObjectText = "Status: Closed"
end
end
elseif v.Name == "InsidePrompt" then
local prox = v
local green = prox.Parent.Parent.Green
local red = prox.Parent.Parent.Red
local Storage = prox.Parent.Parent.Parent
local In = Storage.Orange.In.Union
local Out = Storage.Orange.Out.Union
local rollup = Storage.Orange.RollUp
local update = Storage.oclosed
wait(0.2)
if In.Transparency == 0 then
green.Material = "Neon" -- door opened
green.Color = Color3.fromRGB(33, 243, 22)
green.Massless = false
red.Material = "Glass"
red.Color = Color3.fromRGB(153, 0, 74)
In.Transparency = 1
In.CanCollide = false
Out.Transparency = 1
Out.CanCollide = false
prox.ObjectText = "Status: Open"
rollup.Transparency = 0
update.TextScaled = true
In.creak:Play()
else
green.Material = "Glass" -- door closed
green.Color = Color3.fromRGB(0, 138, 99)
green.Massless = true
red.Material = "Neon"
red.Color = Color3.fromRGB(186, 64, 8)
In.Transparency = 0
In.CanCollide = true
Out.Transparency = 0
Out.CanCollide = true
prox.ObjectText = "Status: Closed"
rollup.Transparency = 1
update.TextScaled = false
In.bang:Play()
end
-- the arrows
local useprox = v.Parent.InsidePrompt
local Storage = useprox.Parent.Parent.Parent
local needs = Storage["Hallway Toggle"]
local flat = needs.Flat
local prox = flat.HallPrompt
local green = needs.Green
local red = needs.Red
local In = Storage.Orange.In.Union
wait(0.5)
if In.Transparency == 1 then
green.Material = "Neon" -- door opened
green.Color = Color3.fromRGB(33, 243, 22)
green.Massless = false
red.Material = "Glass"
red.Color = Color3.fromRGB(153, 0, 74)
prox.ObjectText = "Status: Open"
else
if In.Transparency == 0 then
green.Material = "Glass" -- door closed
green.Color = Color3.fromRGB(0, 138, 99)
green.Massless = true
red.Material = "Neon"
red.Color = Color3.fromRGB(186, 64, 8)
prox.ObjectText = "Status: Closed"
end
end
elseif v.Name == "OuterPrompt" then
local prox = v
local green = prox.Parent.Parent.Green
local red = prox.Parent.Parent.Red
local Storage = prox.Parent.Parent.Parent
local In = Storage.Open.In.Union
local Out = Storage.Open.Out.Union
local rollup = Storage.Open.RollUp
wait(0.2)
if In.Transparency == 0 then
green.Material = "Neon" -- door opened
green.Color = Color3.fromRGB(33, 243, 22)
green.Massless = false
red.Material = "Glass"
red.Color = Color3.fromRGB(153, 0, 74)
In.Transparency = 1
In.CanCollide = false
Out.Transparency = 1
Out.CanCollide = false
prox.ObjectText = "Status: Open"
rollup.Transparency = 0
In.creak:Play()
else
green.Material = "Glass" -- door closed
green.Color = Color3.fromRGB(0, 138, 99)
green.Massless = true
red.Material = "Neon"
red.Color = Color3.fromRGB(186, 64, 8)
In.Transparency = 0
In.CanCollide = true
Out.Transparency = 0
Out.CanCollide = true
prox.ObjectText = "Status: Closed"
rollup.Transparency = 1
In.bang:Play()
end
end
end)
end
end
So previously every proximityprompt needed its own script, so I had 200 scripts saying the same thing. Then I decided to let one script do all the work by using a for loop, and it worked fine because I connected each iterated instance to the triggered event. But what if I wanted the function to activate when a bool changed from true to false? Then I would need the function to connect to both the Triggered event and Bool.Changed event.
So the issue I’m having is this method doesn’t work in a for loop for some reason