Raycasting Between Two Attachments Returning Nil

Hello everyone,

I am new to using raycasts and I am trying to create a script that allows me to tell if there is an object between two set attachments.

Unfortunately right now the result of the ray cast is always returning nil in every circumstance or arrangement despite the code seeming to look okay

Here is my code:

local blade = workspace:WaitForChild("blade",5)

local top = blade.Top
local base = blade.Base

local function castRay()
	local direction = Vector3.new(0,-100,0) --top.Position - base.Position
	local params = RaycastParams.new()
	params.FilterDescendantsInstances = {blade}
	params.IgnoreWater = true;
	params.FilterType = Enum.RaycastFilterType.Blacklist
	local res = workspace:Raycast(base.Position,direction,params)


Any help is appreciated, thanks in advance

1 Like

maybe the heartbeat is causing too many raycasts to be called?

I need an error log so I can figure this out

I just figured it out

The problem was i was using the Position property of the attachment which is a local relative position system. I needed to use the WorldPosition property

1 Like