I'm going to go with it's fine to do what you are saying, as I am sure that you mean tone instead of key
- changing a note in your melody from one tone to another tone within the same scale is fine,
- changing to a tone outside of your scale may also be fine and even dictated by your chord progression
as with all things musical, however, without a concrete example it is only guesswork as to whether what you have done is reasonable or not