The reason you would use electrical energy to create hydrogen to use in a car comes down to how far you can go on one "fill".
With hydrogen you can go much farther because batteries simply can't - and likely won't - contain anywhere near the energy.
Hydrogen is tricky to work with and store...