Hi guys, I wrote a simple function that fires a ray given a start CFrame and an end CFrame. The filter is set to exclude all the baseparts in the living player folder in the workspace. For some reason though, the code keeps printing no result, and returning the EndPos argument no matter what, even if I am certain the ray is going straight through a wall. Does anybody know what’s wrong here?
function QuickCast(StartPos, EndPos, Length)
local Filter = RaycastParams.new()
Filter.FilterType = Enum.RaycastFilterType.Exclude
for _, V in pairs(workspace.Alive:GetDescendants()) do
if V:IsA("BasePart") then
Filter:AddToFilter(V)
end
end
local SP = (StartPos.Position - EndPos.Position).Unit * Length
local Result = workspace:Raycast(StartPos.Position, SP, Filter)
local Ending
if Result then
Ending = CFrame.new(Result.Position)
else
print("No result")
Ending = EndPos
end
return Ending
end