Ultimately, the preference for 4 or 6 legs within a given environment would come down to the environmental pressures themselves. In its simplest form, the problem is one of agility v. strength.
In an environment where your animal has a survival strategy akin to 'tanking', or making themselves as strongly armoured and stable as possible, 6 legs will win because there are more feet on the ground, and that serves the double purpose of providing a more stable platform and more supportive strength for the armour plating you are going build on your animal. Think animals like Stegosaurus, Ankylosaurus, etc. These were heavy, slow creatures whose survival strategy was based on their ability to withstand attack long enough to give them time to damage or scare off their attackers with their spiked or clubbed tails respectively, and of course their scary roar (we assume).
Such animals would have actually benefited from 6 legs because they could have grown bigger (more legs supporting their weight) but the tradeoff is that they would have been slower. In other words, you're trading speed for toughness.
The extra legs add mass to your body, meaning that they adversely impact the square cube law. That is to say, as you scale up your animal it finds it more difficult to jump and agilely change direction faster because there is more mass by comparison to the relative size of torso for a creature with fewer limbs.
BUT; that's not the real impact of the square cube law for increasing limbs on creatures you want to give speed and agility.
More legs doesn't equal more speed
Adding more legs may increase your torque as a creature, meaning that you can climb steeper mountains or go for longer on the straight, but it simply cannot increase your upper speed. It might increase your acceleration from a standing start in some cases, but that's it. In point of fact, it can actually lower your upper speed because you have to find a gait that combines more feet in an efficient sequence and that's not easy to do.
Torso size can be smaller with fewer limbs
Fewer limbs mean that your torso only has to handle a smaller set of appendage points, so not only do the limbs you have get to be more spread out (and therefore not in the way of each other when running), but the torso can be proportionally smaller meaning that you get the real benefit of the square cube law by decreasing body size generally. Also, the shape of the torso can be squatter, allowing you to fit more organs in a more compact space without disrupting gait. All this leads to a leaner, faster creature suited to the open plains.
Ever seen a Praying Mantis holding its food with its front appendages? It's not standing but it's doing the closest thing it can to that. Why? Because when man's first ancestors started standing, they only had to tilt one pair of appendages; their legs. In doing so, the spine goes from horizontal to vertical immediately (oversimplification, but true enough for the purposes of this answer) because the hips served as a pivot point.
If your 6 legged creatures want the advantage of height as a vantage point from which to see their enemies approaching, which is largely what proto-man was doing, then you don't have a pivot point because you have 2 sets of hips to contend with. Unless you have a spine with a hinge in it, you're not going to stand upright. Remember, centaurs would have a very complicated spinal column that doesn't really work in the real world because you're essentially attaching an extra spine where the horse's neck normally goes. This is highly unlikely to develop in concert with using the forelegs as hands, and would be a separate and more complicated journey to uprightness than a simple pivot in the hips.
So; the general rule of thumb is;
6 legs - Tankers, slow and cumbersome, but heavily armoured and strong.
4 legs - Faster and agile, more likely to stand upright and develop 'hands' at some point.
As such, your 4 legs are more likely to develop on savannahs or in a world of ambush predators, your 6 legs will develop around large predators that prefer a fight before dinner.