Need help with my Raycast filter not filtering correct

Hey! I need help with my Raycast filter not filtering correct.

I have tried a lot of different things but can’t really get my head around it as I am kinda new to Raycasts.

So I want my Raycast not to detect player characters but it’s currently not working, here is the code:

							local unitRay  = workspace.CurrentCamera:ScreenPointToRay(mouse.X, mouse.Y, 0)
							
							local players = game:GetService("Players")
							
							local Blacklist = {}
							
							for i,v in pairs(players:GetChildren()) do
								
								local character = v.Character
								
								table.insert(Blacklist, character)
								
								for e,f in pairs(character:GetChildren()) do
									
									if f:IsA("BasePart") then

										table.insert(Blacklist, f)

									end	
									
								end
								
							end
							
							local raycastParams = RaycastParams.new()
							raycastParams.FilterDescendantsInstances = Blacklist
							raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
					
							local ray = Ray.new(unitRay.Origin, unitRay.Direction * 1000, raycastParams)
							
							local hit, pos, normal = game:GetService("Workspace"):FindPartOnRay(ray, PickedObject)

I manged to fix the issue by changing the “FindPartOnRay” to → “FindPartOnRayWithIgnoreList” and I also swaped out the “PickedObject” for my “Blacklist”, I had no idea that I had to filter both functions

I’m surprised that worked, that method is deprecated and shouldn’t work with raycast params. Raycast params aren’t even what’s expected for the third parameter of Ray.new, it shouldn’t have taken into account any white/blacklist specifications. I think you mixed up Ray.new with workspace:Raycast, switching would give you an all-in-one method of creating a ray with origin and direction and actually casting it in the workspace.

https://create.roblox.com/docs/reference/engine/classes/WorldRoot#Raycast

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