I have a brick that fires a ray. The ray should fire in the direction the brick is facing, so whenever the direction the brick is facing change, the direction of the rays being fired should change too, however I don't know what to write to make this happen please help.
This is what it looks like: Raycasting Brick
and another: Raycasting Brick2
while wait() do
local ray = Ray.new(script.Parent.CFrame.p, (Vector3.new(0, 0, -60) - script.Parent.CFrame.p).unit * 300) -- Problem is here
local part, endPoint = workspace:FindPartOnRay(ray, script.Parent)
local beam = Instance.new("Part", workspace)
beam.BrickColor = BrickColor.new("Bright red")
beam.FormFactor = "Custom"
beam.Material = "Neon"
beam.Transparency = 0.25
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
local distance = (script.Parent.CFrame.p - endPoint).magnitude
beam.Size = Vector3.new(0.3, 0.3, distance)
beam.CFrame = CFrame.new(script.Parent.CFrame.p, endPoint) * CFrame.new(0, 0, -distance / 2)
print(part)
game:GetService("Debris"):AddItem(beam, 0.1)
end

2 comments
Thank you~!
Np