[SOLVED] Raycast not working properly

hi

i’ve looked everywhere and couldn’t find any solutions to this problem

i have a script that constantly checks if there’s a wall in front of a part via raycasting but it only seems to fire when the part was only just created

not the full script, if you need more just let me know, there’s an extra tween that moves the object which is why it says tween:Pause()

(orb is the part, orbs is the folder)

local wallCheck = coroutine.create(function()
	
	local raycastParams = RaycastParams.new()
	
	raycastParams.FilterDescendantsInstances = {script.Parent, workspace.PartsToFilter, target.Character}
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	
	while orb.Activated.Value == true do
		
		local raycastResult = workspace:Raycast(orb.Position, orb.CFrame.LookVector * 5, raycastParams)
		
		if raycastResult then
			
			tween:Pause()
			
			local destroyGoal = {}
			destroyGoal.Transparency = 1
			
			local destroyInfo = TweenInfo.new(0.25, Enum.EasingStyle.Linear)
			
			local destroyTween = TweenService:Create(orb, destroyInfo, destroyGoal)
			
			destroyTween:Play()
			
			orb.Activated.Value = false
			
			wait(0.25)
			
			orb.Parent = orbs
			
			break
			
		end
		
		wait()
		
	end
	
end)

coroutine.resume(wallCheck)

ok nevermind, somehow it just fixed itself for absolutely no reason at all

strange. now it’s happening again. no idea what’s going on

In your FilterDescendantsInstances, you add script.Parent.
Is the script.Parent in this instance the workspace? Then you’re blacklisting everything within the workspace.

If you could, add a print(script.Parent) before you assigned FilterDescendantsInstances

no, this script is parented to a model

Could you print out the raycastResult in the while loop and tell me what info pops up when it gets near a wall?

from previous testing, i don’t even think the raycast is hitting anything but i’ll try

just like i thought. nothing printed

Could you add print("orb_activated", orb.Activated.Value) to the top.

it’s being set to true just before the part i put on the post but i did it anyway. as expected resulted in it printing true

i’ve even tried getting rid of the raycast params but it still isn’t working

Alright, just to make sure that the LookVector is oriented properly.
Anchor the orb from moving then run this:

local Part = Instance.new("Part")
Part.Anchored = true
Part.Size = Vector3.new(2, 2, 2)
Part.CFrame = orb.CFrame * CFrame.new(orb.CFrame.LookVector * 5)
Part.Parent = workspace

If the orb is oriented properly the Part should appear infront of where you expect the collision to happen.

i’m afraid i’ve even tried that too and it just put the part in front of it like it should have

Then just increase the ray length until it starts hitting stuff at that point lol.

tried that too, i’m really not sure what’s going on here. i’ve tried this exact method on other parts and it worked fine

Checking one more thing, when you did the print(raycastResult) was it outputting ANYTHING?
Because at a minimum it should be outputting nil.

it was outputting nil. really not sure why it isn’t detecting anything, might just rewrite the code and see if it starts working

for some reason it seems to only hit stuff when it was first created and then it just starts ignoring stuff, i’ve even put a print to see if the loop is repeating and it is

huh. it seems that when it’s only the one part on its own it acts fine. what i’m doing is i’m making it spam parts towards the player but it seems to work when there’s only one part

Alright I think I figured it out. Give this a shot:

local raycastResult = workspace:Raycast(
			orb.Position,
			CFrame.new(
				orb.Position,
				(orb.CFrame * CFrame.new(1, 0, 0)).Position
			).LookVector * 5,
			raycastParams
		)