Invalid argument #2 to 'new' (Vector3 expected, got nil)?

I keep getting this error!
image

Here is where the error leads:

bullet.CFrame = CFrame.new(gunPos, Position)*CFrame.new(0,0,-Dist/2)

What is the “Position” exactly? In my guess its not set correctly.

1 Like
local Params = RaycastParams.new()
Params.CollisionGroup = "blackListedParts"
Params.FilterType = Enum.RaycastFilterType.Blacklist
local Part, Position = workspace:Raycast(gunPos, mousePos, Params)

Raycast returns a RaycastResult which has the Position as a property.

local result = workspace:Raycast(args)
if (result) then
	local Position = result.Position
end
3 Likes

0 is not a Vector3. If you want to extend the distance then just do(im assuming Dist is a Vector3:

bullet.Position = CFrame.new(gunPos, Position).Unit * -Dist

I guess that you need a Vector3 in the CFrame.
For example:

CFrame.new(Vector3.new(2, 2, 2))