In the current script, the animation loop for the button icon transparency runs repeatedly even when the element is not visible, leading to unnecessary CPU load. This optimization has been made to calculate the animation only when the element is visible.
I’m learning scripting, so it’s possible that I’m wrong.
Before:
task.spawn(function()
local elapsed = 1
while dashboard and dashboardButton and dashboard._instance do
if not dashboard._instance.Visible then
elapsed = 1
end
local alpha = math.abs(elapsed % 2 - 1) * 0.7
dashboardButtonIcon.ImageTransparency = -(math.cos(math.pi * alpha) - 1) / 2
elapsed += task.wait()
end
end)
After
task.spawn(function()
local elapsed = 1
while dashboard and dashboardButton and dashboard._instance do
if dashboard._instance.Visible then
local alpha = math.abs(elapsed % 2 - 1) * 0.7
dashboardButtonIcon.ImageTransparency = -(math.cos(math.pi * alpha) - 1) / 2
end
elapsed += task.wait()
end
end)