Raycast returning nil?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Raycast for normal

  2. What is the issue? Raycast returns nil for seemingly no reason?

  3. What solutions have you tried so far? I’ve looked through most of the topics about that problem but it didn’t help

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local Hit = game.Workspace:GetPartsInPart(Hitbox)
	local HitList = {}
	--Find Humanoids in the hitbox
	for i, v in pairs(Hit) do
		if v.Parent:FindFirstChild("Humanoid") then
			
			if v.Parent:FindFirstChild("State"):GetAttribute("Iframe") == true then break end
			
			if Blockable == true or Blockable == nil then 

				if v.Parent:FindFirstChild("State"):GetAttribute("Block") == true then --check if enemy is blocking
					local RayCastParams = RaycastParams.new()
					RayCastParams.FilterType = Enum.RaycastFilterType.Include
					RayCastParams.IncludeInstances = {v.Parent.HumanoidRootPart}
					local startpos = plr.Character.HumanoidRootPart.Position
					local endpos = v.Parent.HumanoidRootPart.Position
					local distance = (startpos - endpos).Magnitude
					local rayResult = workspace:Raycast(startpos,(startpos - endpos).Unit * distance, RayCastParams)
					print(rayResult)
					if rayResult then
						print(rayResult)

						if rayResult.Normal == Vector3.new(0,0,1) then
							print("Front")
						end
						
					end
					
				end
				
			end
			if not table.find(HitList, v.Parent) and v.Parent.Name ~= plr.Name then
				table.insert(HitList, v.Parent)
			end
		end
	end

here’s most of the script

it’s in modulescript and called by server

I think you need to use endpost-startpos

1 Like

Nope, still returns nil. even with those values reversed

I dont really think this is change a lot but I would always use Params.FilterDescendantsInstances.

Also why do you need to do this local distance = (startpos - endpos).Magnitude and this (startpos - endpos).Unit * distance instead of just using endpos - startpos

1 Like

I don’t know, just saw people use that and it fixed things, also I need specifically HumanoidRootPart not the whole model, that’s why I use IncludeInstances

Ok nevermind changing it to FilterDescendantsInstances actually fixed it, thanks

1 Like