[Moto G Q&A, Help & Troubleshooting] Scontrerasmer:
Works until running the script

It all works until running the flash5.1.bat script, then it fails, I'll give you the log and see if you can help me

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe flash partition gpt.bin
target max-sparse-size: 256MB
sending 'partition' (32 KB)...
OKAY [ 0.026s]
writing 'partition'...
(bootloader) Preflash validation failed
FAILED (remote failure)
finished. total time: 0.328s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe flash motoboot motoboot.img
target max-sparse-size: 256MB
sending 'motoboot' (1953 KB)...
OKAY [ 0.116s]
writing 'motoboot'...
(bootloader) Motoboot: Unknown partition name
(bootloader) Preflash validation failed
FAILED (remote failure)
finished. total time: 0.151s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe reboot-bootloader
rebooting into bootloader...
OKAY [ 0.003s]
finished. total time: 0.003s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>pause
Presione una tecla para continuar . . .

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe flash partition gpt.bin
target max-sparse-size: 256MB
sending 'partition' (32 KB)...
OKAY [ 0.026s]
writing 'partition'...
(bootloader) Preflash validation failed
FAILED (remote failure)
finished. total time: 0.371s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe flash motoboot motoboot.img
target max-sparse-size: 256MB
sending 'motoboot' (1953 KB)...
OKAY [ 0.112s]
writing 'motoboot'...
(bootloader) Motoboot: Unknown partition name
(bootloader) Preflash validation failed
FAILED (remote failure)
finished. total time: 0.148s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe flash logo logo.bin
target max-sparse-size: 256MB
sending 'logo' (295 KB)...
OKAY [ 0.066s]
writing 'logo'...
(bootloader) Permission denied
FAILED (remote failure)
finished. total time: 0.086s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe flash boot boot.img
target max-sparse-size: 256MB
sending 'boot' (10240 KB)...
OKAY [ 0.439s]
writing 'boot'...
(bootloader) Permission denied
FAILED (remote failure)
finished. total time: 0.466s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe flash recovery recovery.img
target max-sparse-size: 256MB
sending 'recovery' (10240 KB)...
OKAY [ 0.451s]
writing 'recovery'...
(bootloader) Permission denied
FAILED (remote failure)
finished. total time: 0.456s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe flash system system.img_sparsechunk.0
target max-sparse-size: 256MB
sending 'system' (257719 KB)...
OKAY [ 9.463s]
writing 'system'...
(bootloader) Permission denied
FAILED (remote failure)
finished. total time: 9.481s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe flash system system.img_sparsechunk.1
target max-sparse-size: 256MB
sending 'system' (257506 KB)...
OKAY [ 9.568s]
writing 'system'...
(bootloader) Permission denied
FAILED (remote failure)
finished. total time: 9.587s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe flash system system.img_sparsechunk.2
target max-sparse-size: 256MB
sending 'system' (250727 KB)...
OKAY [ 9.316s]
writing 'system'...
(bootloader) Permission denied
FAILED (remote failure)
finished. total time: 9.338s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe flash system system.img_sparsechunk.3
target max-sparse-size: 256MB
sending 'system' (189925 KB)...
OKAY [ 7.069s]
writing 'system'...
(bootloader) Permission denied
FAILED (remote failure)
finished. total time: 7.096s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe flash modem NON-HLOS.bin
target max-sparse-size: 256MB
sending 'modem' (60236 KB)...
OKAY [ 2.307s]
writing 'modem'...
(bootloader) Permission denied
FAILED (remote failure)
finished. total time: 2.358s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe erase modemst1
erasing 'modemst1'...
(bootloader) Invalid partition name modemst1
FAILED (remote failure)
finished. total time: 0.010s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe erase modemst2
erasing 'modemst2'...
(bootloader) Invalid partition name modemst2
FAILED (remote failure)
finished. total time: 0.034s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe flash fsg fsg.mbn
target max-sparse-size: 256MB
sending 'fsg' (661 KB)...
OKAY [ 0.115s]
writing 'fsg'...
(bootloader) Permission denied
FAILED (remote failure)
finished. total time: 0.147s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe erase cache
erasing 'cache'...
(bootloader) Invalid partition name cache
FAILED (remote failure)
finished. total time: 0.033s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe erase userdata
erasing 'userdata'...
(bootloader) Invalid partition name userdata
FAILED (remote failure)
finished. total time: 0.043s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe oem fb_mode_clear
...
OKAY [ 0.002s]
finished. total time: 0.003s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>mfastboot.exe reboot-bootloader
rebooting into bootloader...
OKAY [ 0.021s]
finished. total time: 0.022s

C:\Users\Sebastián\Desktop\moto g\XT1040_PEREGRINE_RETLA_5.1_LPB23.13-35_cid12_CFC.xml>pause
Presione una tecla para continuar . . .

I'm pretty sad as I can't afford to buy a new phone

It's a Peregrine XT 1040