Problem with while loop: overlapping visuals
https://gyazo.com/394ccb7e360cc414803219e160102c81
Here you can see the intended visual play normally at first
But when I click Priority again after clicking a different light sequence then it starts to overlap with the previous Priority sequence
Main, Server
function evaluateSeatAttrEnabled(seat:VehicleSeat, LightsContainer:Folder)
if seat:GetAttribute('Enabled') == true then
PatternBehaviors.modifyLightColor(LightsContainer, Color3.fromRGB(255, 255, 255))
else
PatternBehaviors.modifyLightColor(LightsContainer, Color3.fromRGB(0, 0, 0))
end
resetTransparency(LightsContainer, 0)
cancelAllPartTweens(LightsContainer)
end
function evaluateCurrentSeatState(seat: VehicleSeat)
local LightsContainer = seat.Parent:FindFirstChild('Lights')
local lastPattern = seat:GetAttribute('CurrentPattern')
-- Set the lights based on the seat's enabled state before checking the pattern
evaluateSeatAttrEnabled(seat, LightsContainer)
if seat:GetAttribute('Enabled') == true then
while seat:GetAttribute('CurrentPattern') == lastPattern and seat:GetAttribute('Enabled') == true do
local patternModule = require(LightPatterns[seat:GetAttribute('PatternType')]:FindFirstChild(seat:GetAttribute('CurrentPattern')))
patternModule.activate(LightsContainer)
task.wait()
end
else
print('Disabled')
-- Ensure that we reset the lights immediately when disabled
evaluateSeatAttrEnabled(seat, LightsContainer)
end
- Here is my code in the Priority Module:
local PatternBehaviors = require(game:GetService('ReplicatedStorage').Modules.PatternBehaviors)
local module = {}
function module.activate(lightsContainer: Folder)
local tweenTime = 2
for i = 1, 5 do
lightsContainer:FindFirstChild("L"..i).Transparency = 0
end
print('tweening priority')
PatternBehaviors.modifyLightColor(lightsContainer, Color3.fromRGB(255,100,0))
for _, part in (lightsContainer:GetChildren()) do
if part:IsA('BasePart') then
PatternBehaviors.Tween(part, {tweenTime}, {Color = Color3.fromRGB(255, 20, 0)})
end
end
for i = 1, 5 do
PatternBehaviors.Tween(lightsContainer:FindFirstChild("L"..i), {tweenTime}, {Transparency = 1})
end
task.wait(tweenTime)
end
return module
The setup looks like this:
Any ideas? on how to solve?