Hello! How is it going? I am wondering if my color changing script tween’s code can be improved.
So basically, this will be used inside of a menu, and the buttons change color. If that menu is being selected, the tween will play on the menu, and make it green. If not, the menu will turn white.
local TweenService = game:GetService("TweenService")
local ColorChangingTweenInfo = TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
for _, Buttons in pairs(script.Parent:GetChildren()) do
if Buttons:IsA("GuiButton") then
Buttons.MouseButton1Click:Connect(function()
for _, Menus in pairs(script.Parent.Parent.ScrollingFrame:GetChildren()) do
if Menus:IsA("Frame") then
Menus.Visible = false
end
if Menus.Name == Buttons.Name then
Menus.Visible = true
end
for _, Button in pairs(script.Parent:GetChildren()) do
if Button:IsA("GuiButton") then
if Button.Name ~= Buttons.Name then
TweenService:Create(Button, ColorChangingTweenInfo, {BackgroundColor3 = Color3.new(1, 1, 1), TextColor3 = Color3.new(0, 0, 0)}):Play()
else
TweenService:Create(Button, ColorChangingTweenInfo, {BackgroundColor3 = Color3.new(0, 0.666667, 0), TextColor3 = Color3.new(1, 1, 1)}):Play()
end
end
end
end
end)
end
end
If you believe there is something I should change, please let me know. Thanks! WE