You have posted a snippet showing only two functions, please read the how to use this forum post, don't post snippets, post complete code.
loop and receiveEvent are functions, they are not "voids". They are functions that return void (ie, nothing).
When you declare sensor within receiveEvent, it is a local variable. So you have a local variable named "sensor" only in scope within receiveEvent and presumably (I say presumably because you haven't posted your global variable declarations, but you say it compiles successfully, and you don't declare "sensor" within loop) also a global one. So in loop it's using the global, but in receiveEvent it's using the local variable.
The solution is to use the global variable in receiveEvent - remove the "int" from the first line.
You must also declare the global sensor variable as volatile, since you are changing it within an ISR.