CFrame.fromMatrix errors when called correctly

CFrame.fromMatrix(Position, XVector, YVector)
-- no error

CFrame.fromMatrix(Position, XVector, YVector, nil)
-- error: invalid argument #4 to 'fromMatrix' (Vector3 expected, got nil)

despite the function’s spec having that last argument be optional.

nil ~= nothing provided, this was stated by somone from staff, but I can’t find that message (search by “nil” can’t give good results)

Yeah, there’s the Void primitive, which isn’t equal to nil. Though I don’t think we can detect “void” in Lua

I think this is because nil itself is considered an argument to the function, so any function that depends on the number of arguments to do different things will have this behavior, including Standard Library functions like math.min:

1 Like

I mean yes, that’s true, but there’s no way for us to check if an argument is void

1 Like

Thank you for reaching out.

For this function, this is by design.
You either provide 3 or 4 arguments, but all have to be of valid type.
Documentation also says that last parameter can be excluded, not that it can be substituted with nil.

local function returnNothing() end
print(select("#", returnNothing())) -- 0
print(select("#", nil)) -- 1
2 Likes