how to make a color changing brick in roblox studio

To create a color-changing brick in Roblox Studio using Lua, you can use the following script:

local brick = script.Parent
local colors = {Color3.new(1, 0, 0), Color3.new(0, 1, 0), Color3.new(0, 0, 1)} -- Define the colors you want to use

local function changeColor()
    local currentColor = brick.BrickColor.Color
    for i, color in ipairs(colors) do
        if currentColor == color then
            local nextColor = colors[(i % #colors) + 1]
            brick.BrickColor = BrickColor.new(nextColor)
            break
        end
    end
end

brick.Touched:Connect(changeColor) -- Call the changeColor function when the brick is touched

This script creates a color-changing brick that cycles through the defined colors when touched.