Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is Vector3 recognized as a number in CFrame.new(Vec3 pos, Vec3 lookAt)?

self = game.Players.LocalPlayer.Character.Weapon
headCFrame = game.Players.LocalPlayer.Character.Head.CFrame
aimVector = CFrame.new(headCFrame.p, headCFrame.p + headCFrame.lookVector).lookVector

local bullet = Instance.new("Part", workspace)
bullet.CFrame = CFrame.new(self.CFrame.p, self.CFrame.p + aimVector) * 5 -- this line creates the output

The output is bad argument #2 to '?' (Vector3 expected, got number)

I'm making a weapon, and for the purpose of simplifying the thread I just made a bunch of quick variables (in reality self is a part welded to the character's arm) I tested the value of self.CFrame.p + aimVector by checking its .ClassName which printed ClassName is not a valid member of Vector3

I'm not sure if I'm making a stupid mistake or if there's some weird kink to CFrame that I don't know about but help would be greatly appreciated.

1 answer

✓ Accepted answer

On line 6, you attempt to multiply the CFrame by 5. A CFrame cannot be multiplied by a number. A Vector3 value can. Depending on what you're trying to do, you may be able to solve your problem by either removing the 5, or multiplying the Vectors instead.

As for the ClassName issue, ClassName is a property of Instance; Classes such as Vector3 and CFrame don't have it. You can check if it's one of those values using the typeof function.

Hope this helped.

This discussion is preserved as it was. New answers, comments, and votes are closed.