Sizing parts based on raycasts

so there are two parts, part A and part B. part A is like a laser gun, part B is the laser.
is there a way to raycast out of part A and then have part B the size of the raycast?
I would like to have part B as long as possible without going through any walls.

I don’t want to ask for a whole script it makes me feal like a bit of a jerk, but raycasting is above my level and I don’t know what else to do.
I tried learning but to no avail and I tried looking on google and Developer hub but found nothing.
once again, I’m sorry and thank you.

Do you have the position of where the raycast hit?

Have you seen this post? I found it by searching “Roblox part raycast”.

1 Like

basically, I want a part as long as the raycast
because I feel that I didn’t explain it to well

1 Like
local Part = Instance.new("Part")
Part.CFrame = CFrame.lookAt(Origin, RaycastResult.Position)
Part.Position = Origin:lerp(RaycastResult.Position, 0.5)
Part.Size = Vector3.new(1, 1, (RaycastResult.Position - Origin).Magnitude)
1 Like