Raycast returns nil even though there is no way for it to do so?

im working on the melee part of my npc ai script and in order to attack i fire a raycast from the npc’s head towards the players head, but for some reason it returns nil, even though the raycast is fired towards the head and the head is the only whitelisted part?

edit: it does actually work, but rarely. only like 3% of the time, so very inconsistent

local Params = RaycastParams.new()
						Params.FilterType = Enum.RaycastFilterType.Include
						Params.FilterDescendantsInstances = {currentPlr.Character.Head}
						local results = workspace:Raycast(npc.Head.Position,CFrame.new(npc.Head.Position,currentPlr.Character.Head.Position).LookVector,Params)


the LookVector that you’re passing into :Raycast() has a length of 1, which I don’t think you are intending to do…

local RayDistance = 15

local P0 = npc.Head.Position
local P1 = currentPlr.Character.Head.Position
local C0 = CFrame.lookAt(P0, P1)
local results = workspace:Raycast(P0, C0.LookVector * RayDistance, Params)
1 Like

yeah, seems to be working, thanks. it has to be CFrame.lookAt instead of CFrame.LookAt though, in case anyone is having the same issue

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