I made a tool that casts a ray to the position of Mouse.Hit.p, and a beam would appear between the tool's handle and RaycastResult.Position. However sometimes the ray doesn't seem to hit anything at all so the beam doesn't appear. I know for sure that this is is a problem with raycasting and not the beam since WorldRoot:Raycast wont return anything.
-- Only important parts:
local function fireLaser(player, MousePosition)
local origin = LaserPart.Position
local params = RaycastParams.new()
params.FilterDescendantsInstances = GetParamsList:Invoke(player)
params.FilterType = Enum.RaycastFilterType.Blacklist
local rayCast = game.Workspace:Raycast(origin, (MousePosition - origin).Unit, params)
if not rayCast then
return
end
local aPart = AttachmentPart:Clone()
aPart.Script.Disabled = false
aPart.Position = rayCast.Position
aPart.Parent = game.Workspace
Beam.Attachment1 = aPart.Attachment
end
I also made a turret that tracks (p1.CFrame = CFrame.new(p1.Pos, p2.Pos)) the first player that it sees, and the same problem occurs.
-- Only important parts:
local params = RaycastParams.new()
local FDI = script.Parent:GetChildren()
for k, v in pairs(TurretPart:GetChildren()) do
table.insert(FDI, v)
end
params.FilterType = Enum.RaycastFilterType.Blacklist
params.FilterDescendantsInstances = FDI
while true do
-- ...
wait(1)
hit = game.Workspace:Raycast(TurretPart.Position, (hrp.Position - TurretPart.Position).Unit * BulletSpeed, params)
end
Also, there's a Ray object separate from WorldRoot:Raycast, but I don't know how to use it.

2 comments
This works, but defeats the purpose of raycasting. If the player were to go in third person, they would be able to cast the beam through any obstructions. Same for the turret; it can see through obstructions.
why would they be able to cast through obstructions?? the origin would (presumably) be at the barrel of their gun, and if there's something between the player's mouse and the gun, then Raycast will have to return something