local TweenService = game:GetService("TweenService")
local TweenSpeed = 1
local btn = script.Parent:WaitForChild("MainOutline").OpenButton
local pwr = script.Parent:WaitForChild("MainOutline").Power
local Info = TweenInfo.new(TweenSpeed, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
local btn_1 = TweenService:Create(btn, Info, {BackgroundColor3 = Color3.fromRGB(60,60,60)})
local btn_2 = TweenService:Create(btn, Info, {BackgroundColor3 = Color3.fromRGB(30,30,30)})
local pwr_1 = TweenService:Create(pwr, Info, {BackgroundColor3 = Color3.fromRGB(60,60,60)})
local pwr_2 = TweenService:Create(pwr, Info, {BackgroundColor3 = Color3.fromRGB(40,40,40)})
while true do
btn_1:Play()
pwr_1:Play()
task.wait(1)
btn_2:Play()
pwr_2:Play()
task.wait(1)
end
local function tweenagain()
btn_1:Play()
pwr_1:Play()
task.wait(1)
btn_2:Play()
pwr_2:Play()
task.wait(1)
tweenagain() -- calls itself which makes the function loop
end
it should work
ALSO instead of using task.wait() you can use tween.Completed
Alternatively, only two tweens can be used. Further parameters in tween info include repeat count (-1 is infinite) and reverse. So you play once and let the tween transition in and out continuously absent from any loops.
If you don’t mind, I’d also like to mention that while-loops are more efficient than recursion in this case.
Loops are normally more efficient in terms of memory usage and performance for iterative tasks, and recursive functions can be more suitable for some types of problems - depends on the specific problem at hand and the trade-offs between efficiency and code readability.
Recursive functions create a new stack frame for each call, so they consume more memory depending on how deep recursion is. Which means loops have a more straightforward execution flow and constant memory usage.
Nevertheless, recursion can be great for tree and recursive structures with subproblems that need similar logic done in the function. Hence they can be more elegant, understandable and maintainable in such cases.