UPDATE This has been enabled in Studio as of June 10. We are planning to enable it on live clients and servers on June 14th.
As many of you are aware, we’re working towards making Vector3 a native type in Luau VM. This is motivated by the importance of Vector3 type to code that runs on Roblox and dramatic performance improvements this can bring.
This is already highlighted in the beta post, but to raise awareness we’re making a separate post about a particular part of this change in case this was missed, as it’s a comparatively riskier part of the update:
type() will start returning “vector” for Vector3 inputs, instead of the currently returned “userdata” string
This change will happen over the next few weeks (we’re likely to start doing the rollout next week but it might take a couple weeks to deploy fully). If you have games that rely on type()
to check if a value is Vector3, please change them to use typeof()
- typeof()
will continue to return “Vector3” for Vector3 values as it used to.
If you have any questions for the general Vector3 update, please make them on the thread about the beta instead of this one: Native Luau Vector3 Beta.
Why not continue returning “userdata” from type()?
The core issue is that after the update, Vector3 will not be a userdata and will behave differently compared to actual userdata types - see notes about rawequal
and table key behavior, including GC, in the linked announcement thread.
Given that we can’t keep Vector3 a userdata, we only have two options:
- Lie about the
type()
of Vector3 values in service of backwards compatibility. This will help in some cases, but won’t help in all cases. Additionally this will result in a permanent lie which would make it so that you can’t really rely ontype
to tell if something is a userdata or not - Make it so that
type
correctly communicates the underlying value type, with some risk of breaking existing scripts that rely ontype
instead oftypeof
Based on the information we have today, we believe that changing the behavior of type()
to correctly communicate the underlying type will not result in significant disruption and will be much easier for us long term. Unfortunately, we can’t reliably find all games that may be comparing type()
to userdata
when handling Vector3 values (this usually works by inspecting the value for various members such as Magnitude
via a pcall
); hence, this announcement.
Note that we recommend using typeof
to distinguish between various Roblox types over type
in all cases, as it’s going to give you correct information and will do this much faster than the alternative type
+pcall
approach.