Visualizing ray as a part

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

p.CFrame = CFrame.new(Ray.Origin, res.Position)*CFrame.new(0, 0, -distance/2)

I think you made a typo in the variable “ray” in this line.

1 Like

oooh yeah didnt see that thanks

1 Like

ima mark as solution if it works

1 Like

not getting any errors but its not working

Did you parent it to the Workspace? I don’t see that line in the script.

might be the issue, let me try that

1 Like


thanks man

1 Like