I am trying to make a laser beam that would turn off if something is blocking it, but what ever i do it dosent work.
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
thanks for helping me.
