Raycasting returning nil

the script

what it prints
image


btw i know nothing about raycasting so idk what could be the problem

1 Like

I’m assuming that PlayerPositionToFire is direction, right?

If so, replace it with this:

local PlayerPositionToFire = v.HumanoidRootPart.CFrame.LookVector
1 Like

What does script.Parent link to?

1 Like

script.Parent links to a base part
image
(the tripmine)

PlayerPositionToFire is the direction
tho i changed and it still giving me nil

Ah, I can see your intentions.

If you want to raycast from Tripmine to the player then we would need this formula: (Position2 - Position1)

The Position1 will be the Tripmine’s position while the Position2 will be the HumanoidRootPart’s position. That way, we create a direction that go from Tripmine to player.

The direction can also be shortened by adding a unit to it, making its distance 1 stud.

With all this in mind, we can make this:

local RaycastResult = workspace:Raycast(script.Parent.Position, (v.HumanoidRootPart.Position - script.Parent.Position).Unit * 1.5, params)

Also, are you sure you want to multiply the unit by 1.5? That’s 1.5 studs, which is a very short distance. If you want it to detect at long range, increase the multiplier.

Also something to note: You don’t need to use :GetChildren() inside FilterDescendantsInstances since it will ignore anything along with the instance that’s inside the filter.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.