type(Vector3) returning "vector" instead of "userdata"?

8:13 AM UST

Hello everyone,

I encountered an issue with the built-in Lua function type when working with Vector3. Instead of returning "userdata" as it normally does, it returns "vector".

image

However, calling the type function on a Vector2 still returns "userdata", which adds to my confusion as to why this behavior only affects Vector3 specifically.

image

This is particularly problematic for me because I have a JSON utility module that encodes userdata types into strings for later decoding. This module relies on the type function returning "userdata" for all userdata types.

Has anyone else experienced this issue? Any insights or suggestions would be greatly appreciated.

Thank you for reading, and I hope you have a wonderful day or night!

Yeah it’s weird. It’s not supposed to, but apparently only Vector3 has this behavior: What's the difference between type and typeof? - #11 by 7z99

You can use this custom type function.

local type = function(any: any): string
	return if type(any) == "vector" then "userdata" else type(any)
end

print(type(Vector3.zero))

Edit: Behavior change: type() will start returning 'vector' for Vector3

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.