Help with Raycasting

I’m currently trying to raycast a beam so when it touches a part the beam shortens to the intersection point!

I’ve asked a few people how to do this and still not completed it!
I’ve looked at the roblox docs and still couldn’t understand this. I guess raycast isn’t my strong point.

Any help is appreciated

local Start = script.Parent.Start
local End = script.Parent.End
local Pan = script.Parent.Parent.Parent.Motors.Pan
local Tilt = script.Parent.Parent.Parent.Motors.Tilt

local RayOrigin = Start.Position
local RayDestination = End.Position

local Direction = (RayDestination - RayOrigin).Unit

local ray =, RayDestination)

local function UpdatedPan()


local function UpdatedTilt()
	if ray then
		RayDestination = Vector3(ray.Distance)


When using RayCasting you don’t use “”. You would have to use “workspace:Raycast” :slight_smile:

Thanks mate, Just changed this but still didn’t sort my issue,