Raycast is not being created

local player = game.Players.LocalPlayer
local character = player.CharacterAdded:Wait()

local origin = character:WaitForChild("Head")
local direction = character.Head.CFrame.LookVector * 5

local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {character}
rayParams.FilterType = Enum.RaycastFilterType.Blacklist

local charRay = game.Workspace:Raycast(origin.Position, direction, rayParams)


while true do
	wait()
	
	if charRay then
	
		local hit = charRay.Instance
		
		print("yes ray")
	
		if hit ~= nil then
		
			print("ray hit an object")
			print(hit)
		
		else
		
			print("ray is nil")
		
		end
		
	elseif not charRay then
		
		print("no ray")
		
	end
		
end

I tried running this several times, all i got was “no ray” printing. I don’t know if its broken or if im using it wrong.

Try this

local player = game.Players.LocalPlayer
local character = player.CharacterAdded:Wait()

while true do
	wait()
	local origin = character:WaitForChild("Head")
        local direction = character.Head.CFrame.LookVector * 5

       local rayParams = RaycastParams.new()
       rayParams.FilterDescendantsInstances = {character}
       rayParams.FilterType = Enum.RaycastFilterType.Blacklist
 
       local charRay = game.Workspace:Raycast(origin.Position, direction, rayParams)
	if charRay then
	
		local hit = charRay.Instance
		
		print("yes ray")
	
		if hit ~= nil then
		
			print("ray hit an object")
			print(hit)
		
		else
		
			print("ray is nil")
		
		end
		
	elseif not charRay then
		
		print("no ray")
		
	end
		
end
2 Likes

Thanks a lot. Figured it out before the answer but I still appreciate you taking the time to look through it. Much appreciated.

1 Like