'I want my Text Button’s color on Roblox Studio to fade in and fade out but I’m getting error

I use Lua Roblox and I was trying to make the text button change color from blue to orange fade out and fade in and my script got an error, so what should I do?

Code:

game.StartedGui.ScreenGui.TextButton.Color = ””—- I typed orange color inside these brackets —-
wait(.5)
game.StartedGui.ScreenGui.TextButton.Color = “”—- I typed blue color inside these brackets—-

It is not fading out and in the color is still white. Also, how do I do looping because I don’t want the color to stop changing.



Solution 1:[1]

If I am understanding you right, you want to have the button background color fading from blue to orange and back in an endless loop? Try putting the following LocalScript below the TextButton.

local textButton = script.Parent

local color1 = Color3.fromRGB(128, 128, 255)    -- blue

local color2 = Color3.fromRGB(218, 133, 65)     -- orange

local changeSpeed = 10      -- increase this to make slower 



spawn(function()
    local i = -1
    while true do
        for i=-1,1,1/changeSpeed do
            local f = math.abs(i)
            textButton.BackgroundColor3 = Color3.fromRGB(
                255 * (color1.r + (color2.r - color1.r) * f), 
                255 * (color1.g + (color2.g - color1.g) * f),
                255 * (color1.b + (color2.b - color1.b) * f)
            )
            wait(0.05)                          
        end
    end
end) 

Update:

...or use the really cool Tween Service, as Kylaaa mentioned:

[...]
local changeSpeed = 1      -- increase this to make slower 

textButton.BackgroundColor3 = color1
local tw = game.TweenService:Create(textButton, TweenInfo.new(changeSpeed, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true), { BackgroundColor3 = color2 })
tw:Play()

Solution 2:[2]

game.StartedGui.ScreenGui.TextButton.Color = ””—- I typed orange color inside these brackets —-
wait(.5)
game.StartedGui.ScreenGui.TextButton.Color = “”—- I typed blue color inside these brackets—-

TextButton has no Color porperty.

See https://developer.roblox.com/en-us/api-reference/class/TextButton

Fading is not achieved by switching from one to another color with a 500ms delay. You have to code a smooth transition between both colors.

It's either BackgroundColor3 or any of the other color properties listed there.

Assigning a string doesn't make too much sense and also might cause an error. You have to assign a Color3 datatype.

Solution 3:[3]

game.StarterGui.ScreenGui.TextButton.BackgroundColor3 = Color3.fromRGB(color1) wait(.5) game.StarterGui.ScreenGui.TextButton.BackgroundColor3 = Color3.fromRGB(color2)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Piglet
Solution 3