roblox interpolate color

function lerpColor(color1, color2, alpha)
    local r = color1.R + (color2.R - color1.R) * alpha
    local g = color1.G + (color2.G - color1.G) * alpha
    local b = color1.B + (color2.B - color1.B) * alpha
    return Color3.new(r, g, b)
end

local startColor = Color3.new(1, 0, 0) -- Red
local endColor = Color3.new(0, 0, 1) -- Blue
local alphaValue = 0.5 -- Value between 0 and 1

local interpolatedColor = lerpColor(startColor, endColor, alphaValue)
print(interpolatedColor) -- Prints the interpolated color

Explanation: 1. function lerpColor(color1, color2, alpha) defines a function named lerpColor that takes in two Color3 values (color1 and color2) and a floating-point number alpha. 2. Inside the function: a. local r = color1.R + (color2.R - color1.R) * alpha calculates the interpolated value for the red component. b. local g = color1.G + (color2.G - color1.G) * alpha calculates the interpolated value for the green component. c. local b = color1.B + (color2.B - color1.B) * alpha calculates the interpolated value for the blue component. d. return Color3.new(r, g, b) creates and returns a new Color3 value based on the interpolated red, green, and blue components. 3. local startColor = Color3.new(1, 0, 0) defines a Color3 value representing red. 4. local endColor = Color3.new(0, 0, 1) defines a Color3 value representing blue. 5. local alphaValue = 0.5 sets the alpha value to 0.5 (midway between the two colors). 6. local interpolatedColor = lerpColor(startColor, endColor, alphaValue) calls the lerpColor function with the start color, end color, and alpha value to interpolate between the two colors. 7. print(interpolatedColor) prints the interpolated color to the console.