I am trying to make a laser whitch would stop at certain point were it is blocked by a part.
local origin = script.Parent.Position
local direction = workspace.HUB
local params = RaycastParams.new()
local result = workspace:Raycast(origin, direction)
if result then
local distance = (origin - result.Position).Magnitude
local p = Instance.new("Part")
p.Anchored = true
p.CanCollide = false
p.Size = Vector3.new(0.1, 0.1, distance)
p.CFrame = CFrame.lookAt(origin)*CFrame.new(0, 0, -distance/2)
end

2 comments
You should include what the problem is, now you're just giving us a script and telling us it isn't working. What happens? Do you get any errors? What do you want it to do?
can you copy and paste an error you get from the developer console (if you get any)? it's one of the best ways for me to solve errors