A side note about MP compatibility. If you put replace_object.sqs in the init field of any object, this will be executed in every client and the server. So you will try to delete the same object as many times as machines connected which might not be harmfull, but you are creating as many new objects as machines connected too. I understand that you want to delete the original object only once and to create a replacement object only once too, so you may add:
? !local _obj_to_replace:exit
just before
call compile format ["%1 = ""%2"" createvehicle [0,0,0]", _obj_name, _obj_to_create];