I was making a script that when you pull the lever down, all lights that are in the same folder will turn off/ on. However, for some reason it keeps looping and only turn off one at a time instead of all at the same time.
for _,lightfold in pairs(game.Workspace["Local Objects"].Lights:GetDescendants()) do
if lightfold.Name == "Light Group" then
--Switch Variables
local switch = lightfold.Switch["Light Switch"]
local handle = switch.Handle.Handle
local prompt = handle.ProximityPrompt
local pole = switch.Handle.Pole
local degree = switch.Turn.Value
local cooldown = switch.Cooldown.Value
--Tween
local tween = game:GetService("TweenService")
local goaldown = {}
goaldown.CFrame = pole.CFrame * CFrame.Angles(math.rad(degree), 0, 0)
local goalup = {}
goalup.CFrame = pole.CFrame * CFrame.Angles(0, 0, 0)
local Info = TweenInfo.new(1)
local Down = tween:Create(pole, Info, goaldown)
local Up = tween:Create(pole, Info, goalup)
--The Main Script
prompt.Triggered:Connect(function()
for _,lightmodel in pairs(lightfold:GetDescendants()) do
if lightmodel:IsA'Model' and lightmodel.Name == "Light" then
--Light Variables
local light = lightmodel.Lights
local glow = light.SpotLight
--Turn it off or on
if prompt.ActionText == "Turn Off" then
Down:Play()
glow.Enabled = false
light.BrickColor = BrickColor.new("Dark stone grey")
light.Material = "SmoothPlastic"
prompt.Enabled = false
print("The light is turned off")
wait(cooldown)
prompt.ActionText = "Turn On"
prompt.Enabled = true
elseif prompt.ActionText == "Turn On" then
Up:Play()
glow.Enabled = true
light.BrickColor = BrickColor.new("Medium stone grey")
light.Material = "Neon"
prompt.Enabled = false
print("The light is turned On")
wait(cooldown)
prompt.ActionText = "Turn Off"
prompt.Enabled = true
end
end
end
end)
end
end
This is a video showing what I mean, but you need to download it.
robloxapp-20220509-1824146.wmv (3.5 MB)