Ok so I have a script that returns the a UnitRay of the Mouse, and when you press the the "/" key to chat, the UnitRay becomes NAN,NAN,NAN. I've tried many ways to tell if the UnitRay is nil, but none of them work and my script ends up erroring. Is there any way to tell if the number is nil?
Note: I've tried tonumber(UnitRay)
, pcall(function() local Test = 2 * UnitRay end)
, and other methods
A number cannot be nil
- it's a number.
NaN's name is "not a number" . It is a number value nonetheless.
(NaN is C's name for it; Lua calls it -1.#IND
)
NaN is a number; NaN is not nil
.
An easy way to check if a value x
is NaN is to compare it to itself; this is because NaN ~= NaN
.
function isNaN(x) return x ~= x; end
Note that this extends to Vector3 values; if any component is NaN then this function will also return true
, but otherwise false
.