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 = Ray.new(RayOrigin, RayDestination)

local function UpdatedPan()

end

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


Pan.Changed:Connect(UpdatedPan)
Tilt.Changed:Connect(UpdatedTilt)

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

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