Well, AI is pretty broad even for this.
I’m not sure whether you’re just using logic bricks or python. If you’re using logic bricks you shouldn’t have this problem. But if you’re using python this is what you have to add…
import GameLogic as g
c = g.getCurrentController()
space = c.getSensor("space")
motion = c.getActuator("Motion")
If you try that example in blender, if you didn’t have the else statement and pressed the space bar, the object would keep going. With the else statement applied it turns the actuator off, so it’ll stop moving and behave properly.
If you need more specific help, you’d have to elaborate more on your AI.