Alright. So, I have a raycast. It should be a simple projection from Point A to Point B and then returns the position it hit, or nil
if it hits the void. Right?
I have a Raycast
that starts at one position of an instance, follows the LookVector
of the Instance
's CFrame
and then has parameters to stop it from hitting itself or particular bits around it.
However the Params
variable seems to disagree unless I have done something horribly wrong. Whenever the Raycast
tries to not hit the part it starts from or some slight parts around it, it will just immediately go nil
, not even go and hit the next closest part, just nil
outright. And it has driven me insane trying to fix it.
The error goes something like this when it nil
s
[script location]:[line]: attempt to index nil with 'Position'
Now for a code sample:
local RayCastParamsVariable = RaycastParams.new()
RayCastParamsVariable.FilterType = Enum.RaycastFilterType.Blacklist
RayCastParamsVariable.FilterDescendantsInstances = {
PartNearRaycastedPart1,
PartNearRaycastedPart2,
PartRaycastedFrom1,
PartRaycastedFrom2}
print(RayCastParamsVariable.FilterDescendantsInstances)
print(RayCastParamsVariable.FilterType)
local RayCastResult1 = workspace:Raycast(PartRaycastedFrom1.Position, (PartRaycastedFrom1.CFrame.LookVector * 25), RayCastParamsVariable)
local RayCastResult2 = workspace:Raycast(PartRaycastedFrom2.Position, (PartRaycastedFrom2.CFrame.LookVector * 25), RayCastParamsVariable)
Messing around with the params variable has hurt my brain a lot.
Say the parts Raycasted
from are not in the table but the parts around them are, the Raycast
then hits the parts Raycasted
from. If both of them are in the Params
variable it returns nil
, it also returns a completely wrong value which I don’t want if those nearby parts are excluded from the table.
To put it simpler:
The blacklist function doesn’t want to cooperate with me and instead makes my Raycasts
return nil
and also makes certain instances cause the Raycast
to return nil
even if it doesn’t go into the void.
Extra notes:
There is no way for the Raycasts
to hit the void, I have put several parts surrounding the area of the Raycast
which would result in the Raycast
hitting them if it were to have somehow escaped the intended area.
Removing the Params
variable from the Raycast
results in it working fine but the Raycast
will immediately hit the parts around the origin point as they are not blacklisted.
Edit: Feel free to request any other bits of info that might help an effort to resolve the issue, I’m completely open to give info that might prove useful.