Your code works ok for single player games. When you click one of the entities on the client, you have to set a var to a certain value; send that var to the server and it (the server) will move the unit on the client.