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

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

Asked by 8 years ago
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

Log in to vote
0
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago
Edited 8 years ago

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.

Ad

Answer this question