Back to Library
Utility Nov 22, 2025

Rainbow Vehicle

T
by terrorsoul

Cycles the color of every block in a player's vehicle

LUA
function UpdateRainbowVehicle(playerId)
    -- Get the vehicle
    local structure = tm.players.OccupiedStructure(playerId)
    
    if structure ~= nil then
        -- Calculate a color based on current time
        local time = tm.os.GetTime()
        local hue = (time * 0.5) % 1.0 -- 0.5 controls speed
        
        -- Convert HSV to RGB
        local rainbowColor = tm.color.HSVToRGB(hue, 1, 1)
        
        -- Apply to all blocks
        local blocks = structure.GetBlocks()
        for _, block in pairs(blocks) do
            block.SetPrimaryColor(rainbowColor)
        end
    end
end

function update()
    UpdateRainbowVehicle(0)
end

Discussion

Please log in to post a comment.