I got this error while trying to accessing this module:
Workspace.ModuleScript:29: bad argument #1 to 'new' (Vector3 expected, got userdata)
Why am I getting this error i'm using the CFrame constructor "CFrame.new" and not some Vector3 constructor nor value?
Table = {} Table.TweenCFrame = function(part, endP, time) time = time / 0.03 startP = part.CFrame xFact = (endP.x - startP.x) / time yFact = (endP.y - startP.y) / time zFact = (endP.z - startP.z) / time coroutine.resume(coroutine.create(function() for i = startP.x, endP.x, xFact do wait() part.CFrame = CFrame.new(i, part.CFrame.y, part.CFrame.z) * CFrame.Angles(part.CFrame:toEulerAnglesXYZ()) end end) ) coroutine.resume(coroutine.create(function() for i = startP.y, endP.y, yFact do wait() part.CFrame = CFrame.new(part.CFrame.x, i, part.CFrame.z) * CFrame.Angles(part.CFrame:toEulerAnglesXYZ()) end end) ) coroutine.resume(coroutine.create(function() for i = startP.z, endP.z, zFact do wait() part.CFrame = CFrame.new(part.CFrame.x, part.CFrame.y, i) * CFrame.Angles(part.CFrame:toEulerAnglesXYZ()) end end) ) part.CFrame = CFrame.new(endP) * CFrame.Angles(part.CFrame:toEulerAnglesXYZ()) end return Table --Blockoo --Edited by Zobomafoo
CFrame.new( value )
requires value
to be a Vector3 (hence, "Vector3 expected").
It "got" (you "gave" it) a userdata -- which means some other kind of ROBLOX object.
The thing in question was endP
, which is a CFrame -- not a Vector3. To get the position of a CFrame, you can access its .p
property, hence the construction would look like
CFrame.new( endP.p )