Hey lincolnsalles, most probably, the problem is on this code:
BG - x- <512 / BG - Setx to BG.x + 1024
/ chao - Setx to chao.x + 1024
You are telling the program to Set the X for both objects whenever the BG's X position meets the desired condition.
So, for example: if you change the "chao" speed to be slower than "BG", when "BG" X position is lower than 512, both ("BG" and "chao") will have their positions changed.
To fix that, you will have to check the condition for each object individually. For example:
BG - x-< 512 / BG - Set X to BG.x + 1024
chao - x-< 512 / chao - Set X to chao.x + 1024
Note: To avoid repeating yourself to every single object, you can make use of Families.