Help with correcting a lazer system

Im working on a lazer weapon that will shoot a beam forward but will stop when it hits something cancollide true.

however because of the new raycasting system that was recently added, im having trouble using it.

right now if the lazer hits something cancollide false, instead of passing through it just doesnt fire at all.
if the lazer doesnt hit anything, it wont fire at all.

I want to be able to form the beam along the ray that was casted even if it doesnt hit anything while still ignoring cancollide false parts.

here is the code:

while true do

local origin = script.Parent.Position
local goal = script.Parent.CFrame.LookVector * 400

local params =
params.FilterType = Enum.RaycastFilterType.Blacklist
local visualbeam ="Part")
visualbeam.CanCollide = false
visualbeam.Anchored = true
visualbeam.Size =,2,2)
visualbeam.BrickColor ="Royal purple")
visualbeam.Material = Enum.Material.Neon
visualbeam.Name = "LazerBeam"

local filterlist = {}
for i = 1, 20 do
local part = workspace:Raycast(origin,goal,params)
if part and part.Instance:IsA("BasePart") and part.Instance.CanCollide == false then
params.FilterDescendantsInstances = filterlist
local v = (origin - part.Instance.Position)
visualbeam.CFrame = + 0.5*v, origin)
visualbeam.Size =, part.Instance.Size.Y,v.Magnitude)
elseif part and part.Instance:IsA("BasePart") and part.Instance.CanCollide == true then
visualbeam.Parent = game.Workspace
local v = (origin - part.Instance.Position)
visualbeam.CFrame = + 0.5*v,origin)
visualbeam.Size =, visualbeam.Size.Y,v.Magnitude)


if visualbeam then


could someone help walk me through this as the new raycasting system is new to me and doing things like ignore parts with certain properties have become a lot more complex.

It’s a little hard to read since there’s no indenting, but I think the problem is that the new raycast system returns a RaycastResult object instead of a part.

Would change to this:

local result = workspace:Raycast(origin, goal, params)
if result then
    local part = result.Instance

I reccommend trying FastCast. It does basically the same thing that you are trying to do but it has a lot of features and stuff and it’s easy to use.

ok, ill check that out and see if fastcast would be a better option.