StartBlinkingEvent.Event:Connect(function()
repeat
for _,Lights in pairs(LightsTable) do
if Lights:IsA("BasePart") then
Lights.BrickColor = BrickColor.new("Really red")
end
end
wait(IntervalInSeconds)
for _,Lights in pairs(LightsTable) do
if Lights:IsA("BasePart") then
Lights.BrickColor = BrickColor.new("Medium stone grey")
end
end
wait(IntervalInSeconds)
until StopBlinkingEvent.Event
end)
When the event “StartBlinking” is fired, the lights are suppose to blink between Red and Grey, and I want then to keep blinking untill the “StopBlinkingEvent” is fired.
until StopBlinkingEvent.Event
However, it does not work. It only plays the code once then stops. Nothing in output. How do i achieve this?
You could try using a while loop (or repeat like you done), and have a connection setup that changes the value of a variable, which can toggle the loop:
i.e.
StartBlinkingEvent.Event:Connect(function()
local Active = true
StopBlinkingEvent.Event:Once(function()
Active = false
end)
while Active do
-- Your blinking code here
end
end)
Heres the porrtion of the code first, with your modifications in it
local IntervalInSeconds = 0.4
for _,Lights in pairs(LightsTable) do
if Lights:IsA("BasePart") then
Lights.BrickColor = BrickColor.new("Lime green")
end
end
local Active
StartBlinkingEvent.Event:Connect(function()
Active = true
StopBlinkingEvent.Event:Once(function()
Active = false
for _,Lights in pairs(LightsTable) do
if Lights:IsA("BasePart") then
Lights.BrickColor = BrickColor.new("Lime green")
end
end
end)
while Active do
for _,Lights in pairs(LightsTable) do
if Lights:IsA("BasePart") then
Lights.BrickColor = BrickColor.new("Really red")
end
end
wait(IntervalInSeconds)
for _,Lights in pairs(LightsTable) do
if Lights:IsA("BasePart") then
Lights.BrickColor = BrickColor.new("Medium stone grey")
end
end
wait(IntervalInSeconds)
end
end)
local IntervalInSeconds = 0.4
for _,Lights in pairs(LightsTable) do
if Lights:IsA("BasePart") then
Lights.BrickColor = BrickColor.new("Lime green")
end
end
local Active
StartBlinkingEvent.Event:Connect(function()
Active = true
StopBlinkingEvent.Event:Once(function()
Active = false
for _,Lights in pairs(LightsTable) do
if Lights:IsA("BasePart") then
Lights.BrickColor = BrickColor.new("Lime green")
end
end
end)
while Active do
for _,Lights in pairs(LightsTable) do
if Lights:IsA("BasePart") then
Lights.BrickColor = BrickColor.new("Really red")
end
end
if not Active then break end
wait(IntervalInSeconds)
for _,Lights in pairs(LightsTable) do
if Lights:IsA("BasePart") then
Lights.BrickColor = BrickColor.new("Medium stone grey")
end
end
if not Active then break end
wait(IntervalInSeconds)
end
end)