Add warnings to improperly used `Vector3.new` constructor

I’m sure this applies to other constructors, but Vector3.new is particularly bad.

Pop quiz: What are the results of these constructors?

Vector3.new(0)
Vector3.new("cat")
Vector3.new(Vector3.new(1, 2, 3))
Vector3.new(CFrame.new(1, 2, 3))
Vector3.new(BrickColor.Blue())

The answer to all of them is that they’re the same as Vector3.new(0, 0, 0).

Any non-number input (including nil) is just treated like a 0. This is insane and I’m sure has lead to countless wastes of time, especially for learners.

Because erroring on these misuses would be backward incompatible, and no doubt these mistakes live in many front page games, I am suggesting the use just causes a warning, something like

expected number as ‘x’ argument to Vector3.new, but got Vector3

Only the three-number Vector3.new(number, number, number), the zero-argument Vector3.new(), and possibly the three-nil Vector3.new(nil, nil, nil) constructors should be spared the warning.

20 Likes

And Vector3.new(x) and Vector3.new(x,y)

basically it should work the same, except non-number non-nil values get the warning/error

1 Like

I don’t think Vector3.new(x, y) should be spared the warning. That’s most likely the result of a typo omitting one of the axis – and not necessarily the z. It is not too laborious to fix your code to use Vector3.new(x, y, 0) or otherwise just live with the warning.

For example, the Wiki only documents the no-argument and three-argument constructor. I don’t think there’s any official basis to believe that a two argument constructor should have any particular meaning

2 Likes