Can't manage to make visible ray

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I just want a laser going until it touches a part.
  2. What is the issue? Include screenshots / videos if possible!
    It’s acting in a confusing way.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried switching places on stuff but it won’t work.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
   local Start = script.Parent
local End = game.Workspace.End

local rayCastParams =

local Origin = Start.Position
local Direction = Start.CFrame.LookVector * 20

local rayCastResult = workspace:Raycast(Origin, Direction)

if rayCastResult then
	local Part ="Part")
	local EndPosition = rayCastResult.Instance.Position
	local midPoint = Origin + EndPosition / 2
	local Size = (EndPosition - Start.Position).Magnitude
	Part.Parent = game.Workspace
	Part.Anchored = true
	Part.CFrame =, Start.Position)
	Part.Size =, 1, Size)
	Part.Name = "Laser"

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

hi, raycasts also return the hitPosition which you can use to get the length of the laser

local hitPart, hitPos = workspace:Raycast(Origin, Direction)
local Length, Orientation = (Start.Position-hitPos).magnitude,, hitPos)
local Part ="Part")
Part.CFrame = Orientation * cframe(0, 0, -Length/2)
Part.Size =, 0.13, Length)

Is there any simpler way? Because I just figured out the math used for old raycasting methods and it doesn’t work anymore because I tried using it here, if not then thanks anyways.

Simpler way to get a visible raycast? If so, then no, not really.

Guess I will have to spend another year learning the maths of this and not forgetting.

1 Like