This is due to how multi values work. @Jack_999 this is not a bug, just a quirk of lua.
unpack
returns all of the contents of a table from index 1
to #table
, like an ipairs
loop, so, it works as multiple values.
In lua, when multiple values are simplified into one, for example, like this: (1, 2, 3)
the first value is selected. The reason unpack is cutting out the second and third values is basically because lua treats call(), something
as two values, whereas it treats call()
itself with no commas as multiple values (if it returns multiple values when the call finishes), and the reason it works on the end is kind of for the same reason, it treats each bit as a single value up until that last bit where you do the function call, and then it doesn’t have commas in front.
It’s sort of because lua “sees” the commas before the function is called.
You could just do something like this:
local function PutTogether(d)
local vector = (d:GetPivot() * CFrame.new(-5,0,0)).Position
return vector.X, vector.Y, vector.Z, "hi"
end
And, a minor criticism, but, you probably don’t want to be turning a vector into a table anyways, it probably isn’t ideal for performance or memory, or your programming, except maybe if you’re reusing the table so you can modify the components without creating new vectors. I’m not sure that that’s faster anymore with the new native Vector3 stuff either but I haven’t tested.
If you use that in your code a lot, I might suggest something like this:
local function unpackVector3(vector)
return vector.X, vector.Y, vector.Z
end