Ok here is the problem, I have a simple lever script and it is tied to 2 lights in a hallway, when the lever is flipped on, the lights turn on. I want to replicate this on a larger scale, having a much longer hallway with many lights that each turn on at different random intervals (0.1 to 1 second.), how would I go about achieving this? I created a simple for i, v in pairs loop that gets the descendants of the folder where all the lights are, but how would I make them turn on individually and delay them, they are all named the same, leftlight and rightlight. Here is the script:
--Locals
local TweenService = game:GetService("TweenService")
local Values = script.Parent:WaitForChild("Values")
local Functional = Values:WaitForChild("Functional")
local LeverState = Values:WaitForChild("LeverState")
local ResetOnChange = Values:WaitForChild("ResetOnChange")
local ProximityPrompt = script.Parent:WaitForChild("MainLever"):WaitForChild("LeverHandle"):WaitForChild("Attachment"):WaitForChild("ProximityPrompt")
local Rotator = script.Parent:WaitForChild("Rotator")
local Pull = Rotator:WaitForChild("Pull")
local Error = Rotator:WaitForChild("Error")
local LightPart = script.Parent:WaitForChild("Light"):WaitForChild("LightPart")
local PointLight = LightPart:WaitForChild("Attachment"):WaitForChild("PointLight")
local TriggerOverflow = false
--Tweens
local Info = TweenInfo.new(
0.7,
Enum.EasingStyle.Quint,
Enum.EasingDirection.InOut,
0,
false,
0
)
local PropertyTable = {
CFrame = Rotator.CFrame
}
local TweenHandleOff = TweenService:Create(Rotator, Info, PropertyTable)
local Info = TweenInfo.new(
0.7,
Enum.EasingStyle.Quint,
Enum.EasingDirection.InOut,
0,
false,
0
)
local PropertyTable = {
CFrame = Rotator.CFrame * CFrame.Angles(math.rad(67.5), 0, 0)
}
local TweenHandleOn = TweenService:Create(Rotator, Info, PropertyTable)
--Scripting
ProximityPrompt.Triggered:Connect(function()
if TriggerOverflow == false then
TriggerOverflow = true
ProximityPrompt.Enabled = false
wait()
TriggerOverflow = false
if Functional.Value == true then
if LeverState.Value == false then
LeverState.Value = true
Pull:Play()
TweenHandleOn:Play()
TweenHandleOn.Completed:Wait()
LightPart.Color = Color3.fromRGB(57, 216, 28)
PointLight.Color = Color3.fromRGB(0, 255, 0)
else
LeverState.Value = false
Pull:Play()
TweenHandleOff:Play()
TweenHandleOff.Completed:Wait()
LightPart.Color = Color3.fromRGB(216, 43, 30)
PointLight.Color = Color3.fromRGB(255, 0, 0)
end
else
if LeverState.Value == true then
if ResetOnChange.Value == true then
Pull:Play()
TweenHandleOff:Play()
TweenHandleOff.Completed:Wait()
Error:Play()
Error.Ended:Wait()
Pull:Play()
TweenHandleOn:Play()
TweenHandleOn.Completed:Wait()
else
LeverState.Value = false
Pull:Play()
TweenHandleOff:Play()
TweenHandleOff.Completed:Wait()
LightPart.Color = Color3.fromRGB(216, 43, 30)
PointLight.Color = Color3.fromRGB(255, 0, 0)
end
else
Pull:Play()
TweenHandleOn:Play()
TweenHandleOn.Completed:Wait()
Error:Play()
Error.Ended:Wait()
Pull:Play()
TweenHandleOff:Play()
TweenHandleOff.Completed:Wait()
end
end
wait(0.125)
ProximityPrompt.Enabled = true
end
end)