1) If the topic is locked via chanserv (or the equivalent) this will only change it temporarily.
2) The client running the code must be opped in the channel.
Code:
on @*:text:!topic*:#:  .topic $chan $$2-