I have tried to design a laser pointer for a gun. My problem is, the part that is the laser does not update fast enough to stay in line with the gun:
This is my script:
while true do
local lazer = Ray.new(script.Parent.Position, (script.Parent.Parent.PointerThroughPoint.Position - script.Parent.Position)*300)
distance = (script.Parent.Position - script.Parent.Parent.PointerThroughPoint.Position).Magnitude
local hitpart = workspace:FindPartOnRay(lazer)
local distance2 = distance + 300
p = Instance.new("Part",workspace)
p.Name = "Dart"
p.Anchored = true
p.CanCollide = false
p.Material = "Neon"
p.BrickColor = BrickColor.new("Bright red")
p.Size = Vector3.new(0.1, 0.1, distance2)
p.CFrame = CFrame.lookAt(script.Parent.Position, script.Parent.Parent.PointerThroughPoint.Position)*CFrame.new(0, 0, -distance2/2)
wait()
p:Destroy()
end