Buying a car

I’m 21 and I need to build my credit because I want to start saving for a house, my parents told me I should buy a car to build my credit, but I think that’s a huge unnecessary purchase but I’m really not sure what to think. Any advice on how to better build credit ?