Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with CFrame?

Asked by 9 years ago

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

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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 )
Ad

Answer this question