i have this function which is supposed to visualize a ray as a part but im getting this error:
StarterGui.Placement:250: invalid argument #1 to 'new' (Vector3 expected, got nil)
heres the function, ray stands for the ray and res stands for ray results
local function visualize(ray,res)
if res then
local distance = (ray.Origin - res.Position).Magnitude
local p = Instance.new("Part")
p.Anchored = true
p.CanCollide = false
p.Size = Vector3.new(0.1, 0.1, distance)
p.CFrame = CFrame.new(Ray.Origin, res.Position)*CFrame.new(0, 0, -distance/2)
end
end