Arduino master to arduino slave code not working correctly

Tell us how far the I2C bus is extended. It was designed as a within-one-circuit-board interprocessor/peripheral interface.
You will find that very often on this forum, the problem users present is solved by fixing something in the code that was not originally presented. Hence, it is much preferred* that you provide the entire code, in code tags, so that we may import your code into our IDE to observe compilation, structure, etc. It is of course up to you, but most often providing complete code and as much design info as you can will result in expeditious resolution of your problem.
*- to the extent that many helpers simply 'hang back', or walk away, when a new posting simply contains snippets.
YMMV, of course, but hey, you asked for help.